56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Ulmus\Repository;
|
|
|
|
use Ulmus\{ Query, Adapter };
|
|
use Ulmus\Annotation\Property\Field;
|
|
|
|
trait EscapeTrait
|
|
{
|
|
public function escapeIdentifier(string $identifier) : string
|
|
{
|
|
return $this->escapeField($identifier);
|
|
}
|
|
|
|
public function escapeField(string $identifier) : string
|
|
{
|
|
return $this->adapter->adapter()->escapeIdentifier($identifier, Adapter\AdapterInterface::IDENTIFIER_FIELD);
|
|
}
|
|
|
|
public function escapeFieldList(array $fieldList) : array
|
|
{
|
|
foreach($fieldList as &$list) {
|
|
$list['name'] = $this->escapeField($list['name']);
|
|
|
|
$fieldTag = array_filter($list['tags'] ?? [], fn($item) => $item['object'] instanceof Field)[0]['object'] ?? null;
|
|
|
|
if ( $fieldTag && isset($fieldTag->name) ) {
|
|
$fieldTag->name = $this->escapeField($fieldTag->name);
|
|
}
|
|
}
|
|
|
|
return $fieldList;
|
|
}
|
|
|
|
public function escapeTable(string $identifier) : string
|
|
{
|
|
return $this->adapter->adapter()->escapeIdentifier($identifier, Adapter\AdapterInterface::IDENTIFIER_TABLE);
|
|
}
|
|
|
|
public function escapeDatabase(string $identifier) : string
|
|
{
|
|
return $this->adapter->adapter()->escapeIdentifier($identifier, Adapter\AdapterInterface::IDENTIFIER_DATABASE);
|
|
}
|
|
|
|
public function escapedDatabase() : ? string
|
|
{
|
|
$name = $this->entityResolver->tableAnnotation()->database ?? $this->adapter->adapter()->database ?? null;
|
|
|
|
return $name ? static::escapeDatabase($name) : null;
|
|
}
|
|
|
|
public function escapeSchema(string $identifier) : string
|
|
{
|
|
return $this->adapter->adapter()->escapeIdentifier($identifier, Adapter\AdapterInterface::IDENTIFIER_SCHEMA);
|
|
}
|
|
} |