Item.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Ldap
  17. * @subpackage Schema
  18. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Zend_Ldap_Node_Schema_Item provides a base implementation for managing schema
  24. * items like objectClass and attribute.
  25. *
  26. * @category Zend
  27. * @package Zend_Ldap
  28. * @subpackage Schema
  29. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. abstract class Zend_Ldap_Node_Schema_Item implements ArrayAccess, Countable
  33. {
  34. /**
  35. * The underlying data
  36. *
  37. * @var array
  38. */
  39. protected $_data;
  40. /**
  41. * Constructor.
  42. *
  43. * @param array $data
  44. */
  45. public function __construct(array $data)
  46. {
  47. $this->setData($data);
  48. }
  49. /**
  50. * Sets the data
  51. *
  52. * @param array $data
  53. * @return Zend_Ldap_Node_Schema_Item Provides a fluent interface
  54. */
  55. public function setData(array $data)
  56. {
  57. $this->_data = $data;
  58. return $this;
  59. }
  60. /**
  61. * Gets the data
  62. *
  63. * @return array
  64. */
  65. public function getData()
  66. {
  67. return $this->_data;
  68. }
  69. /**
  70. * Gets a specific attribute from this item
  71. *
  72. * @param string $name
  73. * @return mixed
  74. */
  75. public function __get($name)
  76. {
  77. if (array_key_exists($name, $this->_data)) {
  78. return $this->_data[$name];
  79. } else {
  80. return null;
  81. }
  82. }
  83. /**
  84. * Checks whether a specific attribute exists.
  85. *
  86. * @param string $name
  87. * @return boolean
  88. */
  89. public function __isset($name)
  90. {
  91. return (array_key_exists($name, $this->_data));
  92. }
  93. /**
  94. * Always throws BadMethodCallException
  95. * Implements ArrayAccess.
  96. *
  97. * This method is needed for a full implementation of ArrayAccess
  98. *
  99. * @param string $name
  100. * @param mixed $value
  101. * @return null
  102. * @throws BadMethodCallException
  103. */
  104. public function offsetSet($name, $value)
  105. {
  106. throw new BadMethodCallException();
  107. }
  108. /**
  109. * Gets a specific attribute from this item
  110. *
  111. * @param string $name
  112. * @return mixed
  113. */
  114. public function offsetGet($name)
  115. {
  116. return $this->__get($name);
  117. }
  118. /**
  119. * Always throws BadMethodCallException
  120. * Implements ArrayAccess.
  121. *
  122. * This method is needed for a full implementation of ArrayAccess
  123. *
  124. * @param string $name
  125. * @return null
  126. * @throws BadMethodCallException
  127. */
  128. public function offsetUnset($name)
  129. {
  130. throw new BadMethodCallException();
  131. }
  132. /**
  133. * Checks whether a specific attribute exists.
  134. *
  135. * @param string $name
  136. * @return boolean
  137. */
  138. public function offsetExists($name)
  139. {
  140. return $this->__isset($name);
  141. }
  142. /**
  143. * Returns the number of attributes.
  144. * Implements Countable
  145. *
  146. * @return int
  147. */
  148. public function count()
  149. {
  150. return count($this->_data);
  151. }
  152. }