- Merged stash after pull

This commit is contained in:
mcndave committed 2020-10-16 15:27:54 +00:00
1 parent 114fa5be09
commit efa957fe58
20 files changed
+623 -436

No files matched your search

+17 -2
View File
@@ -2,6 +2,8 @@
namespace Ulmus\Common;
use Ulmus\Annotation\Annotation;
use Ulmus\Migration\FieldDefinition;
use Ulmus\Ulmus,
Ulmus\Adapter\AdapterInterface,
Ulmus\Annotation\Property\Field;
@@ -28,8 +30,8 @@ class EntityField
{
$name = $this->entityResolver->searchFieldAnnotation($this->name, new Field() )->name ?? $this->name;
$name = ( $this->entityResolver->databaseAdapter() ?? Ulmus::$defaultAdapter )->adapter()->escapeIdentifier($name, AdapterInterface::IDENTIFIER_FIELD);
$name = $this->entityResolver->databaseAdapter()->adapter()->escapeIdentifier($name, AdapterInterface::IDENTIFIER_FIELD);
return $useAlias ? "{$this->alias}.$name" : $name;
}
@@ -47,6 +49,19 @@ class EntityField
return false;
}
public static function generateCreateColumn($field) : string
{
$definition = new FieldDefinition($field);
# column_name data_type(length) [NOT NULL] [DEFAULT value] [AUTO_INCREMENT] column_constraint;
return implode(" ", [
$definition->getSqlName(),
$definition->getSqlType(),
]);
}
public static function isObjectType($type) : bool
{
# @ Should be fixed with isBuiltIn() instead, it won't be correct based only on name
+31 -15
View File
@@ -2,7 +2,8 @@
namespace Ulmus\Common;
use Ulmus\Annotation\Annotation,
use Ulmus\Ulmus,
Ulmus\Annotation\Annotation,
Ulmus\Annotation\Classes\Table,
Ulmus\Annotation\Property\Field,
Ulmus\Annotation\Property\Relation;
@@ -123,20 +124,36 @@ class EntityResolver {
return $list;
}
public function tableName() : string
public function tableName($required = false) : string
{
if ( null === $table = $this->getAnnotationFromClassname( Table::class ) ) {
throw new \LogicException("Your entity {$this->entityClass} seems to be missing a @Table() annotation");
$table = $this->tableAnnotation($required);
if ( ( $table->name ?? "" ) === "") {
if ($required) {
throw new \ArgumentCountError("Your entity {$this->entityClass} seems to be missing a `name` argument for your @Table() annotation");
}
}
if ( $table->name === "" ) {
throw new \ArgumentCountError("Your entity {$this->entityClass} seems to be missing a `name` argument for your @Table() annotation");
}
return $table->name;
return $table->name ?? "";
}
public function databaseAdapter() : ? \Ulmus\ConnectionAdapter
public function tableAnnotation($required = false) : Table
{
if ( null === $table = $this->getAnnotationFromClassname( Table::class ) ) {
if ($required) {
throw new \LogicException("Your entity {$this->entityClass} seems to be missing a @Table() annotation");
}
}
return $table;
}
public function databaseName() : string
{
return $this->tableAnnotation(false)->database ?? $this->databaseAdapter()->adapter()->database;
}
public function databaseAdapter() : \Ulmus\ConnectionAdapter
{
if ( null !== $table = $this->getAnnotationFromClassname( Table::class ) ) {
if ( $table->adapter ?? null ) {
@@ -148,18 +165,17 @@ class EntityResolver {
}
}
}
return null;
return Ulmus::$defaultAdapter;
}
public function schemaName() : ? string
public function schemaName(bool $required = false) : ? 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 === "" ) {
if ( $required && ( ( $table->schema ?? "" ) === "" ) ) {
throw new \ArgumentCountError("Your entity {$this->entityClass} seems to be missing a `schema` argument for your @Table() annotation");
}
+1
View File
@@ -9,6 +9,7 @@ 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, false);