Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- /**
- * ILLI
- *
- * @category ILLI_System
- * @package ILLI
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- */
- NAMESPACE ILLI\System;
- USE IteratorAggregate;
- /**
- * ILLI Table
- *
- * array in Storage is limited by init-array; type-safe values (SCALAR IS NOT A TYPE!)
- *
- * @category ILLI_System
- * @package ILLI
- * @subpackage System
- * @namespace ILLI\System
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- * @since 2.0.1
- * @version 3.0.1
- */
- CLASS Table EXTENDS Object IMPLEMENTS IteratorAggregate
- {
- USE \ILLI\Core\tStorage
- {
- tStorage___register as private __storageRegister;
- tStorage___unregister as private __storageUnregister;
- tStorage_get as protected storageGet;
- tStorage_getIterator as public getIterator;
- tStorage_push as private storagePush;
- tStorage_pop as private storagePop;
- tStorage_peek as public storagePeek;
- }
- public function __construct(array $data = array())
- {
- parent::__construct();
- if(NULL === $this->storageGet())
- switch(TRUE):
- case($this instanceOf \ILLI\Core\iStack):
- $this->__storageRegister(new \ILLI\Core\Stack(new \ILLI\Core\Collection($data)));
- break;
- case($this instanceOf \ILLI\Core\iQueue):
- $this->__storageRegister(new \ILLI\Core\Queue(new \ILLI\Core\Collection($data)));
- break;
- case($this instanceOf \ILLI\Core\iArrayList):
- default:
- $this->__storageRegister(new \ILLI\Core\ArrayList(new \ILLI\Core\Collection($data)));
- break;
- endswitch;
- }
- public function __set($index, $value)
- {
- if(FALSE === $this->storageGet()->getCollection()->offsetExists($index))
- return;
- if(TRUE === $this->adapterTriggerExists(__METHOD__))
- return $this->adapterCallAlias(__METHOD__, $index, $value);
- $filtered = $this->filterApply(\ILLI\Core\iFilter::ARGUMENTS, __METHOD__, ['index' => $index, 'value' => $value]);
- $index = $filtered['index'];
- $value = $filtered['value'];
- $old = $this->storageGet()->getCollection()->offsetGet($index);
- $orig = is_object($old) ? get_class($old) : getType($old);
- $new = is_object($value) ? get_class($value) : getType($value);
- if($orig !== $new)
- throw new \Exception('Type mismatch for '.$index.'. original:'.$orig.'; new: '.$new);
- $this->storageGet()->getCollection()->offsetSet($index, $value);
- $this->observerNotify(__METHOD__, $index, $value);
- }
- public function __get($index)
- {
- if(FALSE === $this->storageGet()->getCollection()->offsetExists($index))
- return NULL;
- if(TRUE === $this->adapterTriggerExists(__METHOD__))
- return $this->adapterCallAlias(__METHOD__, $index);
- $filtered = $this->filterApply(\ILLI\Core\iFilter::ARGUMENTS, __METHOD__, ['index' => $index]);
- $index = $filtered['index'];
- $value = $this->storageGet()->getCollection()->offsetGet($index);
- $this->observerNotify(__METHOD__, $index, $value);
- $value = $this->filterApply(\ILLI\Core\iFilter::RESULT, __METHOD__, $value);
- return $value;
- }
- public function toArray()
- {
- return $this->storageGet()->getCollection()->toArray();
- }
- public function __destruct()
- {
- $this->__storageUnregister();
- parent::__destruct();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement