diff --git a/system/database/Databases/Object/Aux/ComplementItem.php b/system/database/Databases/Object/Aux/ComplementItem.php deleted file mode 100644 index 4b6386d..0000000 --- a/system/database/Databases/Object/Aux/ComplementItem.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ - public function count(): int { - return count($this->__data); - } - - /** - * - * @return \Traversable|mixed[] - */ - public function getIterator(): \Traversable { - return new \ArrayIterator($this->__data); - } -} \ No newline at end of file diff --git a/system/database/Databases/Object/Aux/ComplementItemLegacy.php b/system/database/Databases/Object/Aux/ComplementItemLegacy.php deleted file mode 100644 index 1daa822..0000000 --- a/system/database/Databases/Object/Aux/ComplementItemLegacy.php +++ /dev/null @@ -1,32 +0,0 @@ - - */ - public function count() { - return count($this->__data); - } - - /** - * - * @return \Traversable|mixed[] - */ - public function getIterator() { - return new \ArrayIterator($this->__data); - } -} \ No newline at end of file diff --git a/system/database/Databases/Object/Item.php b/system/database/Databases/Object/Item.php index e42fbed..c5a14d5 100644 --- a/system/database/Databases/Object/Item.php +++ b/system/database/Databases/Object/Item.php @@ -8,18 +8,9 @@ namespace Phacil\Framework\Databases\Object; +use ArrayObject; use Phacil\Framework\Databases\Object\ItemInterface as ObjectInterface; -use Traversable; -if (version_compare(phpversion(), "7.1.0", ">=")) { - class ComplementItem extends \Phacil\Framework\Databases\Object\Aux\ComplementItem - { - } -} else { - class ComplementItem extends \Phacil\Framework\Databases\Object\Aux\ComplementItemLegacy - { - } -} /** * {@inheritdoc} @@ -27,7 +18,13 @@ if (version_compare(phpversion(), "7.1.0", ">=")) { * @method mixed getValues(string field, ...) * @package Phacil\Framework\Databases\Object */ -class Item extends ComplementItem implements ObjectInterface { +class Item extends \ArrayObject implements ObjectInterface { + + /** + * + * @var array|null + */ + protected $__data = null; /** * @@ -36,6 +33,7 @@ class Item extends ComplementItem implements ObjectInterface { */ function __construct($data = null) { $this->__data = $data; + parent::__construct($data); return $this; } diff --git a/system/database/Databases/Object/ItemInterface.php b/system/database/Databases/Object/ItemInterface.php index 3c77790..71f6f92 100644 --- a/system/database/Databases/Object/ItemInterface.php +++ b/system/database/Databases/Object/ItemInterface.php @@ -12,6 +12,29 @@ namespace Phacil\Framework\Databases\Object; * @method mixed getValue(string $field) * @package Phacil\Framework\Databases\Object */ -interface ItemInterface extends \Countable, \IteratorAggregate { - +interface ItemInterface extends \Countable, \IteratorAggregate, \Serializable { + /** + * + * @param array $data + * @return $this + */ + public function setData(array $data); + + public function __get($key); + + /** + * + * @param string $key + * @param mixed $value + * @return $this + */ + public function setValue($key, $value); + + /** + * + * @param string $method + * @param string[] $args + * @return mixed + */ + public function __call($method, $args); } \ No newline at end of file diff --git a/system/database/Databases/Object/Result.php b/system/database/Databases/Object/Result.php index 53ecc14..96f1ea4 100644 --- a/system/database/Databases/Object/Result.php +++ b/system/database/Databases/Object/Result.php @@ -172,7 +172,8 @@ class Result extends \ArrayIterator implements ResultInterface { $data = parent::offsetGet($index); - $item = new \Phacil\Framework\Databases\Object\Item($data); + /** @var \Phacil\Framework\Databases\Object\ItemInterface */ + $item = \Phacil\Framework\Registry::getInstance()->create("Phacil\Framework\Databases\Object\ItemInterface", [$data]); return $item; } @@ -182,8 +183,9 @@ class Result extends \ArrayIterator implements ResultInterface { #[\ReturnTypeWillChange] public function current() { - $item = new \Phacil\Framework\Databases\Object\Item(parent::current()); - //$item->setData(parent::current()); + /** @var \Phacil\Framework\Databases\Object\ItemInterface */ + $item = \Phacil\Framework\Registry::getInstance()->create("Phacil\Framework\Databases\Object\ItemInterface", [parent::current()]); + return $item; } diff --git a/system/database/Databases/Object/ResultCacheIterator.php b/system/database/Databases/Object/ResultCacheIterator.php index b7cd9ce..8228bf3 100644 --- a/system/database/Databases/Object/ResultCacheIterator.php +++ b/system/database/Databases/Object/ResultCacheIterator.php @@ -183,7 +183,9 @@ class ResultCacheIterator extends \CachingIterator implements ResultInterface { if(!$data) return null; - $item = new \Phacil\Framework\Databases\Object\Item($data); + /** @var \Phacil\Framework\Databases\Object\ItemInterface */ + $item = \Phacil\Framework\Registry::getInstance()->create("Phacil\Framework\Databases\Object\ItemInterface", [$data]); + return $item; } diff --git a/system/etc/preferences.json b/system/etc/preferences.json index 7f177dc..8558fa2 100644 --- a/system/etc/preferences.json +++ b/system/etc/preferences.json @@ -2,6 +2,7 @@ "preferences": { "Phacil\\Framework\\Databases\\Object\\ResultInterface": "Phacil\\Framework\\Databases\\Object\\Result", "Phacil\\Framework\\Interfaces\\Loader": "Phacil\\Framework\\Loader", - "Phacil\\Framework\\Interfaces\\Url": "Phacil\\Framework\\Url" + "Phacil\\Framework\\Interfaces\\Url": "Phacil\\Framework\\Url", + "Phacil\\Framework\\Databases\\Object\\ItemInterface": "Phacil\\Framework\\Databases\\Object\\Item" } } \ No newline at end of file