- Added a new MsSQL adapter
- Some bugfixes were made within annotations. - Added a new Object Instanciator which allows to manipulate and define how an object from an entity must be instanciated with given value.
This commit is contained in:
1 parent
9df7e65dcf
commit
5bd60129ea
22 files changed
+547
-103
No files matched your search
+71
-6
@@ -12,16 +12,73 @@ use Ulmus\Annotation\Property\Field\{ Id, ForeignKey, CreatedAt, UpdatedAt, };
|
||||
|
||||
trait EntityTrait {
|
||||
|
||||
/**
|
||||
* @Ignore
|
||||
*/
|
||||
protected bool $strictEntityFieldsDeclaration = true;
|
||||
|
||||
/**
|
||||
* @Ignore
|
||||
*/
|
||||
protected array $unmatchedEntityDatasetFields = [];
|
||||
|
||||
/**
|
||||
* @Ignore
|
||||
*/
|
||||
public function __get(string $name)
|
||||
{
|
||||
$entityResolver= $this->resolveEntity();
|
||||
|
||||
# Resolve relations here if one is called
|
||||
if ( null !== ( $relation = $entityResolver->searchFieldAnnotation($name, new Relation() ) ) ) {
|
||||
$order = $entityResolver->searchFieldAnnotationList($name, new OrderBy() );
|
||||
$where = $entityResolver->searchFieldAnnotationList($name, new Where() );
|
||||
|
||||
$baseEntity = $relation->entity();
|
||||
$repository = $baseEntity->repository();
|
||||
|
||||
foreach($where as $condition) {
|
||||
$repository->where($condition->field, $condition->value, $condition->operator);
|
||||
}
|
||||
|
||||
foreach($order as $item) {
|
||||
$repository->orderBy($item->field, $item->order);
|
||||
}
|
||||
|
||||
$field = $relation->key;
|
||||
|
||||
if ( method_exists($this, $filterMethod = "filterRelation$name") ) {
|
||||
$this->$filterMethod($repository);
|
||||
}
|
||||
|
||||
switch($relation->type) {
|
||||
case 'oneToMany':
|
||||
$repository->where( $baseEntity->field($relation->foreignKey), 866); # <<<<<<<<< CHANGE $THIS->ID WITH PROPER NOMENCLATURE
|
||||
|
||||
return $this->$name = $repository->loadAll();
|
||||
|
||||
case 'oneToOne':
|
||||
$repository->where( $baseEntity->field($relation->foreignKey), $this->$field );
|
||||
|
||||
$result = $repository->loadAll();
|
||||
|
||||
if ( count($result) === 0 ) {
|
||||
return $baseEntity;
|
||||
}
|
||||
|
||||
return $this->$name = $result[0];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Ignore
|
||||
*/
|
||||
public function entityFillFromDataset($dataset) : self
|
||||
{
|
||||
$fields = Ulmus::resolveEntity(static::class);
|
||||
$fields = $this->resolveEntity();
|
||||
|
||||
foreach($dataset as $key => $value) {
|
||||
$key = strtolower($key);
|
||||
@@ -43,20 +100,28 @@ trait EntityTrait {
|
||||
elseif ( EntityField::isScalarType($field['type']) ) {
|
||||
$this->{$field['name']} = $value;
|
||||
}
|
||||
elseif ( EntityField::isObjectType($field['type']) ) {
|
||||
$this->{$field['name']} = new $field['type']();
|
||||
elseif ( ! $field['builtin'] ) {
|
||||
$this->{$field['name']} = Ulmus::instanciateObject($field['type'], [ $value ]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Ignore
|
||||
*/
|
||||
public function resolveEntity() : EntityResolver
|
||||
{
|
||||
return Ulmus::resolveEntity(static::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Ignore
|
||||
*/
|
||||
public static function repository() : Repository
|
||||
public static function repository(string $alias = Repository::DEFAULT_ALIAS) : Repository
|
||||
{
|
||||
return Ulmus::repository(static::class);
|
||||
return Ulmus::repository(static::class, $alias, Ulmus::$defaultAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user