ulmus/src/Common/EntityField.php

59 lines
1.4 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Ulmus\Common;
use Ulmus\Ulmus,
Ulmus\Annotation\Property\Field;
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)
{
$this->entityClass = $entityClass;
$this->name = $name;
$this->alias = $alias;
$this->entityResolver = $resolver;
}
public function name($useAlias = true) : string
{
$name = $this->entityResolver->searchFieldAnnotation($this->name, new Field() )->name ?? $this->name;
#return $useAlias ? "{$this->alias}.`{$this->name}`" : "`{$this->name}`"; <-SQL
return $useAlias ? "{$this->alias}.\"{$name}\"" : "\"{$name}\"";
}
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;
}
public function __toString() : string
{
return $this->name();
}
}