| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* A class that gives get/put/clear access to a single entry in an array. |
| 5 |
*/ |
| 6 |
class Dropbox_ArrayEntryStore implements Dropbox_ValueStore |
| 7 |
{ |
| 8 |
/** @var array */ |
| 9 |
private $array; |
| 10 |
|
| 11 |
/** @var mixed */ |
| 12 |
private $key; |
| 13 |
|
| 14 |
/** |
| 15 |
* Constructor. |
| 16 |
* |
| 17 |
* @param array $array |
| 18 |
* The array that we'll be accessing. |
| 19 |
* |
| 20 |
* @param mixed $key |
| 21 |
* The key for the array element we'll be accessing. |
| 22 |
*/ |
| 23 |
public function __construct(&$array, $key) |
| 24 |
{ |
| 25 |
$this->array = &$array; |
| 26 |
$this->key = $key; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Returns the entry's current value or <code>null</code> if nothing is set. |
| 31 |
* |
| 32 |
* @return object |
| 33 |
*/ |
| 34 |
public function get() |
| 35 |
{ |
| 36 |
if (isset($this->array[$this->key])) { |
| 37 |
return $this->array[$this->key]; |
| 38 |
} else { |
| 39 |
return null; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Set the array entry to the given value. |
| 45 |
* |
| 46 |
* @param object $value |
| 47 |
*/ |
| 48 |
public function set($value) |
| 49 |
{ |
| 50 |
$this->array[$this->key] = $value; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Clear the entry. |
| 55 |
*/ |
| 56 |
public function clear() |
| 57 |
{ |
| 58 |
unset($this->array[$this->key]); |
| 59 |
} |
| 60 |
} |
| 61 |
|