63 lines
1.2 KiB
PHP
63 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace NoccyLabs\PulseAudio;
|
|
|
|
use ArrayAccess;
|
|
use IteratorAggregate;
|
|
use Countable;
|
|
|
|
class PropertyList implements ArrayAccess, IteratorAggregate, Countable
|
|
{
|
|
|
|
protected $properties = [];
|
|
|
|
protected $readOnly = false;
|
|
|
|
public function __construct(array $properties=[], $readOnly=false)
|
|
{
|
|
$this->properties = $properties;
|
|
$this->readOnly = $readOnly;
|
|
}
|
|
|
|
public function getIterator()
|
|
{
|
|
return new ArrayIterator($this->properties);
|
|
}
|
|
|
|
public function offsetGet($key)
|
|
{
|
|
if (!array_key_exists($key, $this->properties)) {
|
|
return null;
|
|
// throw new InvalidArgumentException("No such property: {$key}");
|
|
}
|
|
return $this->properties[$key];
|
|
}
|
|
|
|
public function offsetSet($key, $value)
|
|
{
|
|
if ($this->readOnly) {
|
|
return;
|
|
}
|
|
$this->properties[$key] = $value;
|
|
}
|
|
|
|
public function offsetUnset($key)
|
|
{
|
|
if ($this->readOnly) {
|
|
return;
|
|
}
|
|
unset($this->properties[$key]);
|
|
}
|
|
|
|
public function offsetExists($key)
|
|
{
|
|
return array_key_exists($key, $this->properties);
|
|
}
|
|
|
|
public function count()
|
|
{
|
|
return count($this->properties);
|
|
}
|
|
}
|
|
|