ulmus/src/Common/EntityField.php

61 lines
1.5 KiB
PHP
Raw Normal View History

2019-08-21 20:13:00 +00:00
<?php
namespace Ulmus\Common;
use Ulmus\Ulmus,
Ulmus\Adapter\AdapterInterface,
Ulmus\Annotation\Property\Field;
2019-08-21 20:13:00 +00:00
class EntityField
{
public string $name;
public string $entityClass;
public string $alias;
protected EntityResolver $entityResolver;
public function __construct(string $entityClass, string $name, string $alias, EntityResolver $resolver)
2019-08-21 20:13:00 +00:00
{
$this->entityClass = $entityClass;
$this->name = $name;
$this->alias = $alias;
$this->entityResolver = $resolver;
}
2019-08-21 20:13:00 +00:00
public function name($useAlias = true) : string
{
$name = $this->entityResolver->searchFieldAnnotation($this->name, new Field() )->name ?? $this->name;
$name = ( $this->entityResolver->databaseAdapter() ?? Ulmus::$defaultAdapter )->adapter()->escapeIdentifier($name, AdapterInterface::IDENTIFIER_FIELD);
return $useAlias ? "{$this->alias}.$name" : $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
{
# @ 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();
}
}