Initial commit
This commit is contained in:
61
src/PropertyList.php
Normal file
61
src/PropertyList.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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_exist($key, $this->properties)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user