File indexing completed on 2024-12-29 05:27:47

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Ldap
0017  * @subpackage Schema
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * Zend_Ldap_Node_Schema_Item provides a base implementation for managing schema
0025  * items like objectClass and attribute.
0026  *
0027  * @category   Zend
0028  * @package    Zend_Ldap
0029  * @subpackage Schema
0030  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0031  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0032  */
0033 abstract class Zend_Ldap_Node_Schema_Item implements ArrayAccess, Countable
0034 {
0035     /**
0036      * The underlying data
0037      *
0038      * @var array
0039      */
0040     protected $_data;
0041 
0042     /**
0043      * Constructor.
0044      *
0045      * @param array $data
0046      */
0047     public function __construct(array $data)
0048     {
0049         $this->setData($data);
0050     }
0051 
0052     /**
0053      * Sets the data
0054      *
0055      * @param  array $data
0056      * @return Zend_Ldap_Node_Schema_Item Provides a fluent interface
0057      */
0058     public function setData(array $data)
0059     {
0060         $this->_data = $data;
0061         return $this;
0062     }
0063 
0064     /**
0065      * Gets the data
0066      *
0067      * @return array
0068      */
0069     public function getData()
0070     {
0071         return $this->_data;
0072     }
0073 
0074     /**
0075      * Gets a specific attribute from this item
0076      *
0077      * @param  string $name
0078      * @return mixed
0079      */
0080     public function __get($name)
0081     {
0082         if (array_key_exists($name, $this->_data)) {
0083             return $this->_data[$name];
0084         } else {
0085             return null;
0086         }
0087     }
0088 
0089     /**
0090      * Checks whether a specific attribute exists.
0091      *
0092      * @param  string $name
0093      * @return boolean
0094      */
0095     public function __isset($name)
0096     {
0097         return (array_key_exists($name, $this->_data));
0098     }
0099 
0100     /**
0101      * Always throws BadMethodCallException
0102      * Implements ArrayAccess.
0103      *
0104      * This method is needed for a full implementation of ArrayAccess
0105      *
0106      * @param  string $name
0107      * @param  mixed $value
0108      * @return null
0109      * @throws BadMethodCallException
0110      */
0111     public function offsetSet($name, $value)
0112     {
0113         throw new BadMethodCallException();
0114     }
0115 
0116     /**
0117      * Gets a specific attribute from this item
0118      *
0119      * @param  string $name
0120      * @return mixed
0121      */
0122     public function offsetGet($name)
0123     {
0124         return $this->__get($name);
0125     }
0126 
0127     /**
0128      * Always throws BadMethodCallException
0129      * Implements ArrayAccess.
0130      *
0131      * This method is needed for a full implementation of ArrayAccess
0132      *
0133      * @param  string $name
0134      * @return null
0135      * @throws BadMethodCallException
0136      */
0137     public function offsetUnset($name)
0138     {
0139         throw new BadMethodCallException();
0140     }
0141 
0142     /**
0143      * Checks whether a specific attribute exists.
0144      *
0145      * @param  string $name
0146      * @return boolean
0147      */
0148     public function offsetExists($name)
0149     {
0150         return $this->__isset($name);
0151     }
0152 
0153     /**
0154      * Returns the number of attributes.
0155      * Implements Countable
0156      *
0157      * @return int
0158      */
0159     public function count()
0160     {
0161         return count($this->_data);
0162     }
0163 }