Recursive_ArrayAccess

Recursive array class to allow multidimensional array access.

Defined (2)

The class is defined in the following location(s).

/deprecated/includes/libraries/class-recursive-arrayaccess.php  
  1. class Recursive_ArrayAccess implements ArrayAccess { 
  2. /** 
  3. * Internal data collection. 
  4. * @var array 
  5. */ 
  6. protected $container = array(); 
  7.  
  8. /** 
  9. * Flag whether or not the internal collection has been changed. 
  10. * @var bool 
  11. */ 
  12. protected $dirty = false; 
  13.  
  14. /** 
  15. * Default object constructor. 
  16. * @param array $data 
  17. */ 
  18. protected function __construct( $data = array() ) { 
  19. foreach ( $data as $key => $value ) { 
  20. $this[ $key ] = $value; 
  21.  
  22. /** 
  23. * Allow deep copies of objects 
  24. */ 
  25. public function __clone() { 
  26. foreach ( $this->container as $key => $value ) { 
  27. if ( $value instanceof self ) { 
  28. $this[ $key ] = clone $value; 
  29.  
  30. /** 
  31. * Output the data container as a multidimensional array. 
  32. * @return array 
  33. */ 
  34. public function toArray() { 
  35. $data = $this->container; 
  36. foreach ( $data as $key => $value ) { 
  37. if ( $value instanceof self ) { 
  38. $data[ $key ] = $value->toArray(); 
  39. return $data; 
  40.  
  41. /** 
  42. * ArrayAccess Implementation 
  43. **/ 
  44.  
  45. /** 
  46. * Whether a offset exists 
  47. * @link http://php.net/manual/en/arrayaccess.offsetexists.php 
  48. * @param mixed $offset An offset to check for. 
  49. * @return boolean true on success or false on failure. 
  50. */ 
  51. public function offsetExists( $offset ) { 
  52. return isset( $this->container[ $offset ]) ; 
  53.  
  54. /** 
  55. * Offset to retrieve 
  56. * @link http://php.net/manual/en/arrayaccess.offsetget.php 
  57. * @param mixed $offset The offset to retrieve. 
  58. * @return mixed Can return all value types. 
  59. */ 
  60. public function offsetGet( $offset ) { 
  61. return isset( $this->container[ $offset ] ) ? $this->container[ $offset ] : null; 
  62.  
  63. /** 
  64. * Offset to set 
  65. * @link http://php.net/manual/en/arrayaccess.offsetset.php 
  66. * @param mixed $offset The offset to assign the value to. 
  67. * @param mixed $value The value to set. 
  68. * @return void 
  69. */ 
  70. public function offsetSet( $offset, $data ) { 
  71. if ( is_array( $data ) ) { 
  72. $data = new self( $data ); 
  73. if ( $offset === null ) { // don't forget this! 
  74. $this->container[] = $data; 
  75. } else { 
  76. $this->container[ $offset ] = $data; 
  77.  
  78. $this->dirty = true; 
  79.  
  80. /** 
  81. * Offset to unset 
  82. * @link http://php.net/manual/en/arrayaccess.offsetunset.php 
  83. * @param mixed $offset The offset to unset. 
  84. * @return void 
  85. */ 
  86. public function offsetUnset( $offset ) { 
  87. unset( $this->container[ $offset ] ); 
/includes/Libraries/Session/class-recursive-arrayaccess.php  
  1. class Recursive_ArrayAccess implements ArrayAccess { 
  2. /** 
  3. * Internal data collection. 
  4. * @var array 
  5. */ 
  6. protected $container = array(); 
  7.  
  8. /** 
  9. * Flag whether or not the internal collection has been changed. 
  10. * @var bool 
  11. */ 
  12. protected $dirty = false; 
  13.  
  14. /** 
  15. * Default object constructor. 
  16. * @param array $data 
  17. */ 
  18. protected function __construct( $data = array() ) { 
  19. foreach ( $data as $key => $value ) { 
  20. $this[ $key ] = $value; 
  21.  
  22. /** 
  23. * Allow deep copies of objects 
  24. */ 
  25. public function __clone() { 
  26. foreach ( $this->container as $key => $value ) { 
  27. if ( $value instanceof self ) { 
  28. $this[ $key ] = clone $value; 
  29.  
  30. /** 
  31. * Output the data container as a multidimensional array. 
  32. * @return array 
  33. */ 
  34. public function toArray() { 
  35. $data = $this->container; 
  36. foreach ( $data as $key => $value ) { 
  37. if ( $value instanceof self ) { 
  38. $data[ $key ] = $value->toArray(); 
  39. return $data; 
  40.  
  41. /** 
  42. * ArrayAccess Implementation 
  43. **/ 
  44.  
  45. /** 
  46. * Whether a offset exists 
  47. * @link http://php.net/manual/en/arrayaccess.offsetexists.php 
  48. * @param mixed $offset An offset to check for. 
  49. * @return boolean true on success or false on failure. 
  50. */ 
  51. public function offsetExists( $offset ) { 
  52. return isset( $this->container[ $offset ]) ; 
  53.  
  54. /** 
  55. * Offset to retrieve 
  56. * @link http://php.net/manual/en/arrayaccess.offsetget.php 
  57. * @param mixed $offset The offset to retrieve. 
  58. * @return mixed Can return all value types. 
  59. */ 
  60. public function offsetGet( $offset ) { 
  61. return isset( $this->container[ $offset ] ) ? $this->container[ $offset ] : null; 
  62.  
  63. /** 
  64. * Offset to set 
  65. * @link http://php.net/manual/en/arrayaccess.offsetset.php 
  66. * @param mixed $offset The offset to assign the value to. 
  67. * @param mixed $value The value to set. 
  68. * @return void 
  69. */ 
  70. public function offsetSet( $offset, $data ) { 
  71. if ( is_array( $data ) ) { 
  72. $data = new self( $data ); 
  73. if ( $offset === null ) { // don't forget this! 
  74. $this->container[] = $data; 
  75. } else { 
  76. $this->container[ $offset ] = $data; 
  77.  
  78. $this->dirty = true; 
  79.  
  80. /** 
  81. * Offset to unset 
  82. * @link http://php.net/manual/en/arrayaccess.offsetunset.php 
  83. * @param mixed $offset The offset to unset. 
  84. * @return void 
  85. */ 
  86. public function offsetUnset( $offset ) { 
  87. unset( $this->container[ $offset ] );