Merge branch 'master' of https://git.mcnd.ca/mcndave/ulmus
This commit is contained in:
commit
f74d1907d9
21 files changed
+759
-555
No files matched your search
@@ -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(),
|
||||
$definition->getSqlParams(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function isObjectType($type) : bool
|
||||
{
|
||||
# @ Should be fixed with isBuiltIn() instead, it won't be correct based only on name
|
||||
|
||||
@@ -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\Virtual,
|
||||
@@ -128,20 +129,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 ) {
|
||||
@@ -153,18 +170,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");
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class PdoObject extends PDO {
|
||||
public function select(string $sql, array $parameters = []): PDOStatement
|
||||
{
|
||||
static::$dump && call_user_func_array(static::$dump, [ $sql, $parameters ]);
|
||||
|
||||
|
||||
try {
|
||||
if (false !== ( $statement = $this->prepare($sql) )) {
|
||||
$statement = $this->execute($statement, $parameters, false);
|
||||
|
||||
Reference in new issue
Block a user