- 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:
Dave Mc Nicoll committed 2020-01-29 16:11:16 -05:00
1 parent 9df7e65dcf
commit 5bd60129ea
22 files changed
+547 -103

No files matched your search

+3 -2
View File
@@ -27,7 +27,7 @@ class EntityField
# Must use REFLECTION before throwing this value.
# Should first check if it's a relation field, and if it is,
# it's real key must be returned (PK usually)
return $useAlias ? "{$this->alias}.`{$this->name}`" : $this->name;
return $useAlias ? "{$this->alias}.\"{$this->name}\"" : "\"{$this->name}\"";
}
public static function isScalarType($type) : bool
@@ -46,7 +46,8 @@ class EntityField
public static function isObjectType($type) : bool
{
return strpos($type, "\\") !== false;
# @ Should be fixed with isBuiltIn() instead, it won't be correct based only on name
# return strpos($type, "\\") !== false;
}
public function __toString() : string
+58 -1
View File
@@ -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
{
+1
View File
@@ -100,6 +100,7 @@ class ObjectReflection {
if ( $property->hasType() ) {
$current['type'] = $property->getType()->getName();
$current['builtin'] = $property->getType()->isBuiltIn();
$current['nullable'] = $property->getType()->allowsNull();
}
+6 -4
View File
@@ -8,10 +8,13 @@ class PdoObject extends PDO {
public function select(string $sql, array $parameters = []) : PDOStatement
{
#dump($sql, $parameters);
try {
if ( false !== ( $statement = $this->prepare($sql) ) ) {
$statement = $this->execute($statement, $parameters, true);
$statement = $this->execute($statement, $parameters, false);
$statement->setFetchMode(\PDO::FETCH_ASSOC);
return $statement;
}
} catch (\PDOException $e) { throw $e; }
@@ -19,7 +22,6 @@ class PdoObject extends PDO {
public function runQuery(string $sql, array $parameters = []) : PDOStatement
{
# var_dump($sql, $parameters);die();
try {
if ( false !== ( $statement = $this->prepare($sql) ) ) {
return $this->execute($statement, $parameters, true);
@@ -35,9 +37,9 @@ class PdoObject extends PDO {
}
if ( empty($parameters) ? $statement->execute() : $statement->execute($parameters) ) {
# if ( $commit ) {
if ( $commit ) {
$this->commit();
# }
}
return $statement;
}