Merge branch 'master' of https://git.mcnd.ca/mcndave/ulmus
This commit is contained in:
commit
ab582c9318
|
@ -159,6 +159,14 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
|
|||
$pdo->sqliteCreateFunction('length', fn($string) => strlen($string), 1);
|
||||
$pdo->sqliteCreateFunction('lcase', fn($string) => strtolower($string), 1);
|
||||
$pdo->sqliteCreateFunction('ucase', fn($string) => strtoupper($string), 1);
|
||||
$pdo->sqliteCreateFunction('md5', fn($string) => md5($string), 1);
|
||||
$pdo->sqliteCreateFunction('sha1', fn($string) => sha1($string), 1);
|
||||
$pdo->sqliteCreateFunction('sha256', fn($string) => hash('sha256', $string), 1);
|
||||
$pdo->sqliteCreateFunction('sha512', fn($string) => hash('sha512', $string), 1);
|
||||
$pdo->sqliteCreateFunction('whirlpool', fn($string) => hash('whirlpool', $string), 1);
|
||||
$pdo->sqliteCreateFunction('murmur3a', fn($string) => hash('murmur3a', $string), 1);
|
||||
$pdo->sqliteCreateFunction('murmur3c', fn($string) => hash('murmur3c', $string), 1);
|
||||
$pdo->sqliteCreateFunction('murmur3f', fn($string) => hash('murmur3f', $string), 1);
|
||||
$pdo->sqliteCreateFunction('left', fn($string, $length) => substr($string, 0, $length), 2);
|
||||
$pdo->sqliteCreateFunction('right', fn($string, $length) => substr($string, -$length), 2);
|
||||
$pdo->sqliteCreateFunction('strcmp', fn($s1, $s2) => strcmp($s1, $s2), 2);
|
||||
|
|
|
@ -134,7 +134,7 @@ trait SqlAdapterTrait
|
|||
case is_object($value):
|
||||
return Ulmus::convertObject($value);
|
||||
|
||||
case is_array($value):
|
||||
case is_array($value):
|
||||
return json_encode($value);
|
||||
|
||||
case is_bool($value):
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Ulmus\Entity;
|
||||
|
||||
use Ulmus\Common\{ EntityField, EntityResolver };
|
||||
use Ulmus\{ ConnectionAdapter, EntityCollection, Query\QueryBuilderInterface, Repository };
|
||||
|
||||
interface EntityInterface /* extends \JsonSerializable */
|
||||
{
|
||||
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 toCollection() : EntityCollection;
|
||||
public function isLoaded() : bool;
|
||||
public function jsonSerialize() : mixed;
|
||||
public static function resolveEntity() : EntityResolver;
|
||||
public static function repository(string $alias = Repository::DEFAULT_ALIAS, ConnectionAdapter $adapter = null) : Repository;
|
||||
public static function entityCollection(...$arguments) : EntityCollection;
|
||||
public static function queryBuilder() : QueryBuilderInterface;
|
||||
public static function field($name, null|string|bool $alias = Repository::DEFAULT_ALIAS) : EntityField;
|
||||
public static function fields(array $fields, null|string|bool $alias = Repository::DEFAULT_ALIAS, string $separator = ', ') : string;
|
||||
}
|
|
@ -360,7 +360,7 @@ class EntityCollection extends \ArrayObject implements \JsonSerializable {
|
|||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return $this->toArray();
|
||||
return $this->toArray(true);
|
||||
}
|
||||
|
||||
public function append($value) : void
|
||||
|
|
|
@ -4,9 +4,9 @@ namespace Ulmus;
|
|||
|
||||
use Notes\Attribute\Ignore;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Ulmus\{
|
||||
Common\EntityResolver,
|
||||
use Ulmus\{Common\EntityResolver,
|
||||
Common\EntityField,
|
||||
Query\QueryBuilderInterface,
|
||||
SearchRequest\SearchRequestInterface,
|
||||
SearchRequest\SearchRequestPaginationTrait};
|
||||
use Ulmus\Annotation\Classes\{ Method, Table, Collation, };
|
||||
|
@ -28,6 +28,10 @@ trait EntityTrait {
|
|||
|
||||
#[Ignore]
|
||||
public function __construct(array $dataset = null) {
|
||||
if ($dataset) {
|
||||
$this->entityFillFromDataset($dataset);
|
||||
}
|
||||
|
||||
$this->resetVirtualProperties();
|
||||
}
|
||||
|
||||
|
@ -134,12 +138,12 @@ trait EntityTrait {
|
|||
}
|
||||
|
||||
#[Ignore]
|
||||
public function fromArray(iterable $dataset) : self
|
||||
public function fromArray(iterable $dataset) : static
|
||||
{
|
||||
return $this->entityFillFromDataset($dataset);
|
||||
}
|
||||
|
||||
public function entityGetDataset(bool $includeRelations = false, bool $returnSource = false) : array
|
||||
public function entityGetDataset(bool $includeRelations = false, bool $returnSource = false, bool $rewriteValue = true) : array
|
||||
{
|
||||
if ( $returnSource ) {
|
||||
return $this->entityLoadedDataset;
|
||||
|
@ -153,7 +157,10 @@ trait EntityTrait {
|
|||
$annotation = $entityResolver->searchFieldAnnotation($key, [ Attribute\Property\Field::class, Field::class ]);
|
||||
|
||||
if ( isset($this->$key) ) {
|
||||
$dataset[$annotation->name ?? $key] = static::repository()->adapter->adapter()->writableValue($this->$key);
|
||||
$dataset[$annotation->name ?? $key] = $rewriteValue?
|
||||
static::repository()->adapter->adapter()->writableValue($this->$key)
|
||||
:
|
||||
$this->$key;
|
||||
}
|
||||
elseif ( $field['nullable'] ) {
|
||||
$dataset[$annotation->name ?? $key] = null;
|
||||
|
@ -163,7 +170,7 @@ trait EntityTrait {
|
|||
# @TODO Must fix recursive bug !
|
||||
if ($includeRelations) {
|
||||
foreach($entityResolver->properties as $name => $field){
|
||||
$relation = $entityResolver->searchFieldAnnotation($key, [ Attribute\Property\Relation::class. Relation::class ] );
|
||||
$relation = $entityResolver->searchFieldAnnotation($name, [ Attribute\Property\Relation::class, Relation::class ] );
|
||||
|
||||
if ( $relation && isset($this->$name) && ($relation->entity ?? $relation->bridge) !== static::class ) {
|
||||
if ( null !== $value = $this->$name ?? null ) {
|
||||
|
@ -190,7 +197,7 @@ trait EntityTrait {
|
|||
#[Ignore]
|
||||
public function toArray($includeRelations = false, array $filterFields = null) : array
|
||||
{
|
||||
$dataset = $this->entityGetDataset($includeRelations);
|
||||
$dataset = $this->entityGetDataset($includeRelations, false, false);
|
||||
|
||||
return $filterFields ? array_intersect_key($dataset, array_flip($filterFields)) : $dataset;
|
||||
}
|
||||
|
@ -269,7 +276,7 @@ trait EntityTrait {
|
|||
#[Ignore]
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return $this->entityGetDataset();
|
||||
return $this->entityGetDataset(true, false, false);
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
|
@ -294,7 +301,7 @@ trait EntityTrait {
|
|||
}
|
||||
|
||||
#[Ignore]
|
||||
public static function queryBuilder() : QueryBuilder
|
||||
public static function queryBuilder() : QueryBuilderInterface
|
||||
{
|
||||
return Ulmus::queryBuilder(static::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue