2019-08-21 20:13:00 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Ulmus\Common;
|
|
|
|
|
|
|
|
|
|
use Ulmus\Ulmus;
|
|
|
|
|
|
|
|
|
|
class EntityField
|
|
|
|
|
{
|
|
|
|
|
public string $name;
|
|
|
|
|
|
|
|
|
|
public string $entityClass;
|
|
|
|
|
|
|
|
|
|
public string $alias;
|
|
|
|
|
|
|
|
|
|
protected EntityResolver $entityResolver;
|
|
|
|
|
|
|
|
|
|
public function __construct(string $entityClass, string $name, string $alias)
|
|
|
|
|
{
|
|
|
|
|
$this->entityClass = $entityClass;
|
|
|
|
|
$this->name = $name;
|
|
|
|
|
$this->alias = $alias;
|
|
|
|
|
$this->entityResolver = Ulmus::resolveEntity(static::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function name($useAlias = true) : string
|
|
|
|
|
{
|
|
|
|
|
# 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)
|
2020-01-29 21:11:16 +00:00
|
|
|
|
return $useAlias ? "{$this->alias}.\"{$this->name}\"" : "\"{$this->name}\"";
|
2019-08-21 20:13:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function isScalarType($type) : bool
|
|
|
|
|
{
|
|
|
|
|
switch($type) {
|
|
|
|
|
case 'int':
|
|
|
|
|
case 'bool':
|
|
|
|
|
case 'string':
|
|
|
|
|
case 'float':
|
|
|
|
|
case 'double':
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function isObjectType($type) : bool
|
|
|
|
|
{
|
2020-01-29 21:11:16 +00:00
|
|
|
|
# @ Should be fixed with isBuiltIn() instead, it won't be correct based only on name
|
|
|
|
|
# return strpos($type, "\\") !== false;
|
2019-08-21 20:13:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function __toString() : string
|
|
|
|
|
{
|
|
|
|
|
return $this->name();
|
|
|
|
|
}
|
|
|
|
|
}
|