- 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
@@ -4,7 +4,8 @@ namespace Ulmus\Common;
|
||||
|
||||
use Ulmus\Annotation\Annotation,
|
||||
Ulmus\Annotation\Classes\Table,
|
||||
Ulmus\Annotation\Property\Field;
|
||||
Ulmus\Annotation\Property\Field,
|
||||
Ulmus\Annotation\Property\Relation;
|
||||
|
||||
class EntityResolver {
|
||||
|
||||
@@ -78,6 +79,49 @@ class EntityResolver {
|
||||
return $fieldList;
|
||||
}
|
||||
|
||||
public function relation(string $name) : ? array
|
||||
{
|
||||
try{
|
||||
if ( null !== ( $this->properties[$name] ?? null ) ) {
|
||||
foreach($this->properties[$name]['tags'] ?? [] as $tag) {
|
||||
if ( $tag['object'] instanceof Relation ) {
|
||||
return $this->properties[$name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
catch(\Throwable $e) {
|
||||
if ( $throwException) {
|
||||
throw new \InvalidArgumentException("Can't find entity relation's column named `$name` from entity {$this->entityClass}");
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function searchFieldAnnotation(string $field, Annotation $annotationType) : ? Annotation
|
||||
{
|
||||
$found = $this->searchFieldAnnotationList($field, $annotationType);
|
||||
return $found ? $found[0] : null;
|
||||
}
|
||||
|
||||
public function searchFieldAnnotationList(string $field, Annotation $annotationType) : array
|
||||
{
|
||||
$list = [];
|
||||
|
||||
if ( null !== ( $this->properties[$field] ?? null ) ) {
|
||||
foreach($this->properties[$field]['tags'] ?? [] as $tag) {
|
||||
if ( $tag['object'] instanceof $annotationType ) {
|
||||
$list[] = $tag['object'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function tableName() : string
|
||||
{
|
||||
if ( null === $table = $this->getAnnotationFromClassname( Table::class ) ) {
|
||||
@@ -91,6 +135,19 @@ class EntityResolver {
|
||||
return $table->name;
|
||||
}
|
||||
|
||||
public function schemaName() : ? string
|
||||
{
|
||||
if ( null === $table = $this->getAnnotationFromClassname( Table::class ) ) {
|
||||
throw new \LogicException("Your entity {$this->entityClass} seems to be missing a @Table() annotation");
|
||||
}
|
||||
|
||||
if ( $table->name === "" ) {
|
||||
throw new \ArgumentCountError("Your entity {$this->entityClass} seems to be missing a `schema` argument for your @Table() annotation");
|
||||
}
|
||||
|
||||
return $table->schema ?? null;
|
||||
}
|
||||
|
||||
public function primaryKeys() : array
|
||||
{
|
||||
|
||||
|
||||
Reference in new issue
Block a user