32 lines
884 B
PHP
32 lines
884 B
PHP
<?php
|
|
|
|
namespace Ulmus\Attribute;
|
|
|
|
use Ulmus\Common\EntityField;
|
|
use Ulmus\Repository;
|
|
|
|
class Attribute
|
|
{
|
|
public static function handleArrayField(null|\Stringable|string|array $field, null|string|bool $alias = Repository::DEFAULT_ALIAS, string $separator = ', ') : mixed
|
|
{
|
|
if ( is_array($field) ) {
|
|
if (count($field) < 2) {
|
|
throw new \RuntimeException(
|
|
sprintf("Array field must be formed of at least two things, a class name, and a property. (received %s)", json_encode($field))
|
|
);
|
|
}
|
|
|
|
$class = array_shift($field);
|
|
$field[1] ??= $alias;
|
|
|
|
if (is_array($field[0])) {
|
|
$field[] = $separator;
|
|
return $class::fields(...$field);
|
|
}
|
|
|
|
return $class::field(...$field);
|
|
}
|
|
|
|
return $field;
|
|
}
|
|
} |