- Added ArrayOf attributes and DatasetFill/DatasetPull events. ArrayCollection is also working with ArrayOf attributes
This commit is contained in:
1 parent
fd5d31fa17
commit
009e30eb7e
21 files changed
+322
-43
No files matched your search
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Entity;
|
||||
|
||||
use Ulmus\EntityCollection;
|
||||
|
||||
class ArrayCollection extends EntityCollection implements JsonUnserializable
|
||||
{
|
||||
|
||||
public function jsonUnserialize(array $json): void
|
||||
{
|
||||
$this->fromarray($json);
|
||||
}
|
||||
|
||||
public function fromArray(array $datasets, ? string /*stringable*/ $entityClass = null) : self
|
||||
{
|
||||
foreach($datasets as $dataset) {
|
||||
\ArrayObject::append($dataset);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ interface EntityInterface extends SearchableInterface /* extends \JsonSerializab
|
||||
{
|
||||
public function fromArray(iterable $dataset) : static;
|
||||
public function entityGetDataset(bool $includeRelations = false, bool $returnSource = false) : array;
|
||||
public function toArray($includeRelations = false, array $filterFields = null) : array;
|
||||
public function toArray($includeRelations = false, array $filterFields = []) : array;
|
||||
public function toCollection() : EntityCollection;
|
||||
public function isLoaded() : bool;
|
||||
public function jsonSerialize() : mixed;
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
namespace Ulmus\Entity;
|
||||
|
||||
interface EntityObjectInterface {
|
||||
public function load(...$arguments);
|
||||
public function load(mixed ...$arguments);
|
||||
public function save();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Entity;
|
||||
|
||||
interface EntityValueModifier {
|
||||
public function push(mixed $value, \Notes\Common\ReflectedProperty $property) : mixed;
|
||||
public function pull(mixed $value, \Notes\Common\ReflectedProperty $property) : mixed;
|
||||
}
|
||||
@@ -8,7 +8,7 @@ class Datetime extends \DateTime implements EntityObjectInterface, \JsonSerializ
|
||||
|
||||
public string $format = "Y-m-d H:i:s";
|
||||
|
||||
public function load(...$arguments)
|
||||
public function load(mixed ...$arguments)
|
||||
{
|
||||
$value = $arguments[0];
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Entity;
|
||||
|
||||
interface JsonUnserializable extends \JsonSerializable
|
||||
{
|
||||
public function jsonUnserialize(array $json): void;
|
||||
}
|
||||
@@ -14,6 +14,11 @@ class ObjectInstanciator {
|
||||
elseif ( ($obj = new $type() ) instanceof EntityObjectInterface ) {
|
||||
return $obj->load(...$arguments);
|
||||
}
|
||||
elseif ( ($obj = new $type() ) instanceof JsonUnserializable ) {
|
||||
$obj->jsonUnserialize(json_decode($arguments[0], true));
|
||||
|
||||
return $obj;
|
||||
}
|
||||
else {
|
||||
return new $type(...$arguments);
|
||||
}
|
||||
@@ -24,8 +29,14 @@ class ObjectInstanciator {
|
||||
if ( $obj instanceof EntityObjectInterface ) {
|
||||
return $obj->save();
|
||||
}
|
||||
|
||||
return (string) $obj;
|
||||
elseif ( $obj instanceof \JsonSerializable ) {
|
||||
return json_encode($obj->jsonSerialize());
|
||||
}
|
||||
elseif ( $obj instanceof \Stringable ) {
|
||||
return (string) $obj;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException("Object %s could not be converted as an acceptable format.");
|
||||
}
|
||||
|
||||
public function enum(\UnitEnum $obj)
|
||||
|
||||
@@ -5,11 +5,11 @@ namespace Ulmus\Entity\Sqlite;
|
||||
use Notes\Common\ReflectedProperty;
|
||||
use Ulmus\EntityCollection;
|
||||
|
||||
use Ulmus\{Attribute\Obj\Table};
|
||||
use Ulmus\{Attribute\Obj\Table, Entity\EntityInterface};
|
||||
use Ulmus\Attribute\Property\{Field, Filter, FilterJoin, Relation, Join, Virtual, Where};
|
||||
|
||||
#[Table]
|
||||
class Column
|
||||
class Column implements EntityInterface
|
||||
{
|
||||
use \Ulmus\EntityTrait;
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ namespace Ulmus\Entity\Sqlite;
|
||||
|
||||
use Ulmus\EntityCollection;
|
||||
use Ulmus\Query\{From, Select};
|
||||
use Ulmus\{Attribute\Obj\Table, Repository, Ulmus};
|
||||
use Ulmus\{Attribute\Obj\Table, Entity\EntityInterface, Repository, Ulmus};
|
||||
use Ulmus\Attribute\Property\{Field, Filter, FilterJoin, Relation, Join, Virtual, Where};
|
||||
|
||||
#[Table(name: "sqlite_master")]
|
||||
class Schema
|
||||
class Schema implements EntityInterface
|
||||
{
|
||||
use \Ulmus\EntityTrait;
|
||||
|
||||
|
||||
Reference in new issue
Block a user