123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- /**
- *
- * Cube Framework $Id$ 8qaWRX4fmVzeIuE/7ypLWRJuk20Z8OMS91Wg6xSA2K0=
- *
- * @link http://codecu.be/framework
- * @copyright Copyright (c) 2015 CodeCube SRL
- * @license http://codecu.be/framework/license Commercial License
- *
- * @version 1.4
- */
- /**
- * config object
- */
- namespace Cube\Config;
- abstract class AbstractConfig
- {
- /**
- *
- * the data that the config object holds
- *
- * @var mixed
- */
- protected $_data;
- /**
- *
- * a node of the config array
- *
- * @var string
- */
- protected $_node;
- /**
- *
- * class constructor
- * accepts a file, the location of the config file, and a node, in case we want to only hold a
- * part of the configuration array in the config object
- *
- * @param string $data
- * @param string $node
- */
- public function __construct($data = null, $node = null)
- {
- if ($data !== null) {
- $this->setData($data);
- }
- $this->setNode($node);
- }
- /**
- *
- * get the data held in the config container as an array
- * if a node is not found, return an empty array rather than the whole data array
- *
- * @param string $node
- *
- * @return array
- */
- public function getData($node = null)
- {
- if ($node !== null) {
- $this->setNode($node);
- }
- if ($this->_node !== null) {
- $iterator = new \RecursiveIteratorIterator(
- new \RecursiveArrayIterator($this->_data),
- \RecursiveIteratorIterator::SELF_FIRST);
- foreach ($iterator as $key => $array) {
- if ($key == $this->_node) {
- return $array;
- }
- }
- return array();
- }
- return (array)$this->_data;
- }
- /**
- *
- * set the config object data
- *
- * @param mixed $data
- *
- * @return $this
- */
- public function setData($data)
- {
- $this->clearData();
- $this->addData($data);
- return $this;
- }
- /**
- *
- * clear data
- *
- * @return $this
- */
- public function clearData()
- {
- $this->_data = array();
- return $this;
- }
- /**
- *
- * get the node name
- *
- * @return string
- */
- public function getNode()
- {
- return $this->_node;
- }
- /**
- *
- * set the node for the config array
- *
- * @param string $node
- */
- public function setNode($node)
- {
- $this->_node = $node;
- }
- /**
- *
- * add data
- *
- * @param array $data
- *
- * @return $this
- */
- abstract public function addData($data);
- }
|