This commit is contained in:
Dave Mc Nicoll committed 2020-11-27 12:21:10 -05:00
commit f74d1907d9
21 files changed
+759 -555

No files matched your search

+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\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");
}