Overview

Namespaces

  • Knot
    • Dict
      • Helpers
    • Exceptions
  • None

Classes

  • Knot\Dict
  • Knot\Dict\AbstractDictBody
  • Knot\Dict\ChildDict
  • Knot\Dict\HelperManager
  • Knot\Dict\Helpers\AbstractPHPArrayHelper
  • Knot\Dict\Helpers\PHPArrayChangerHelper
  • Knot\Dict\Helpers\PHPArrayEqualizerHelper
  • Knot\Dict\Helpers\UnderscoreHelper
  • Knot\Dict\ParentDict

Interfaces

  • Knot\Dict\Helpers\HelperInterface

Traits

  • Knot\Dict\ArrayAccessTrait
  • Knot\Dict\CountableTrait
  • Knot\Dict\IteratorAggregateTrait
  • Knot\Dict\PathOperationsTrait

Exceptions

  • Knot\Exceptions\FunctionExecuteException
  • Knot\Exceptions\WrongArrayPathException
  • Knot\Exceptions\WrongFunctionException

Functions

  • ar
  • arr
  • arrRef
  • is_dict
  • Overview
  • Namespace
  • Class
  1: <?php namespace Knot\Dict;
  2: 
  3: use ArrayAccess;
  4: use Countable;
  5: use IteratorAggregate;
  6: use Knot\Exceptions\FunctionExecuteException;
  7: use Knot\Exceptions\WrongArrayPathException;
  8: use Knot\Exceptions\WrongFunctionException;
  9: 
 10: /**
 11:  * PHP ArrayEqualHelper methods
 12:  * @method $this merge( array $array1 = null, array $array2 = null, array $_ = null )
 13:  * @method $this reverse()
 14:  * @method $this values()
 15:  *
 16:  * PHP ArrayChangerHelper methods
 17:  * @method mixed shift()
 18:  * @method mixed unshift( mixed $variable )
 19:  * @method mixed push( mixed $variable )
 20:  */
 21: abstract class AbstractDictBody implements Arrayaccess, Countable, IteratorAggregate {
 22: 
 23:     use ArrayAccessTrait, CountableTrait, IteratorAggregateTrait, PathOperationsTrait;
 24: 
 25:     /**
 26:      * Knot data.
 27:      * @var array
 28:      */
 29:     protected $data;
 30: 
 31:     /**
 32:      * @var AbstractDictBody
 33:      */
 34:     protected $parentArray;
 35: 
 36:     /**
 37:      * @var string
 38:      */
 39:     protected $path = '';
 40: 
 41: 
 42:     /**
 43:      * @return AbstractDictBody
 44:      */
 45:     abstract public function kill();
 46: 
 47: 
 48:     /**
 49:      * @param array            $data
 50:      * @param AbstractDictBody $parent
 51:      * @param                  $path
 52:      */
 53:     public function __construct(array &$data, AbstractDictBody $parent = null, $path = '')
 54:     {
 55:         $this->data        =& $data;
 56:         $this->path        = $path;
 57:         $this->parentArray = $parent;
 58:     }
 59: 
 60: 
 61:     /**
 62:      * @param $key
 63:      * @param $value
 64:      */
 65:     public function __set($key, $value)
 66:     {
 67:         $this->data[$key] = $value;
 68:     }
 69: 
 70: 
 71:     /**
 72:      * @param string|int $key
 73:      *
 74:      * @return mixed|\Knot\Dict\ChildDict
 75:      * @throws \Exception
 76:      */
 77:     public function &__get($key)
 78:     {
 79:         if ( array_key_exists($key, $this->data) )
 80:         {
 81:             $target =& $this->data[$key];
 82:         }
 83:         else
 84:         {
 85:             throw new WrongArrayPathException($key);
 86:         }
 87: 
 88:         if ( is_array($target) )
 89:         {
 90:             $r = new ChildDict($target, $this->childParent(), $this->path($key));
 91: 
 92:             return $r;
 93:         }
 94: 
 95:         return $target;
 96:     }
 97: 
 98: 
 99:     /**
100:      * Call callable data variable.
101:      *
102:      * @param string $method
103:      * @param array  $arguments
104:      *
105:      * @return mixed
106:      * @throws \Exception
107:      */
108:     public function call($method, array $arguments = [ ])
109:     {
110:         if ( ! $this->keyExists($method) || ! is_callable($this->data[$method]) )
111:         {
112:             throw new WrongFunctionException("Wrong function or not callable key!");
113:         }
114: 
115:         $function = $this->data[$method];
116: 
117:         try
118:         {
119:             $arguments = array_merge([ &$this->data ], $arguments);
120: 
121:             return call_user_func_array($function, $arguments);
122:         }
123:         catch (\Exception $e)
124:         {
125:             throw new FunctionExecuteException($method);
126:         }
127:     }
128: 
129: 
130:     /**
131:      * Function list: Helper Libraries!
132:      *
133:      * @param string $method
134:      * @param array  $arguments
135:      *
136:      * @return $this|mixed
137:      * @throws \Exception|WrongFunctionException
138:      */
139:     public function __call($method, $arguments = [ ])
140:     {
141:         try
142:         {
143:             return $this->getHelperManager()->execute($method, $arguments, $this);
144:         }
145:         catch (\Exception $e)
146:         {
147:             throw $e;
148:         }
149:     }
150: 
151: 
152:     /**
153:      * @param mixed $key
154:      *
155:      * @return bool
156:      */
157:     public function __isset($key)
158:     {
159:         return isset( $this->data[$key] );
160:     }
161: 
162: 
163:     /**
164:      * @param mixed $key
165:      */
166:     public function __unset($key)
167:     {
168:         unset( $this->data[$key] );
169:     }
170: 
171: 
172:     /**
173:      * Easy Access for get function!
174:      *
175:      * @param $path
176:      *
177:      * @return mixed
178:      */
179:     public function __invoke($path)
180:     {
181:         return $this->get($path);
182:     }
183: 
184: 
185:     /**
186:      * Only search own data keys.
187:      *
188:      * @param mixed $key
189:      *
190:      * @return bool
191:      */
192:     public function keyExists($key)
193:     {
194:         return isset( $this->data[$key] );
195:     }
196: 
197: 
198:     /**
199:      * @return HelperManager
200:      */
201:     public function getHelperManager()
202:     {
203:         return HelperManager::getInstance();
204:     }
205: 
206: 
207:     /**
208:      * @return int|string
209:      */
210:     public function lastKey()
211:     {
212:         end($this->data);
213: 
214:         return key($this->data);
215:     }
216: 
217: 
218:     /**
219:      * @return array
220:      */
221:     public function &toArray()
222:     {
223:         return $this->data;
224:     }
225: 
226: 
227:     /**
228:      * @return ParentDict
229:      */
230:     public function copy()
231:     {
232:         $_data = $this->data;
233: 
234:         return new ParentDict($_data, null, '');
235:     }
236: 
237: 
238:     /**
239:      * @return $this
240:      */
241:     public function childParent()
242:     {
243:         return $this;
244:     }
245: 
246: }
247: 
API documentation generated by ApiGen