Compare commits

..

No commits in common. "ab582c931879347ee6989188950266a4e7ee2f27" and "ab1d7e4f5ba909907d503c89be8e6b2e7f0cd039" have entirely different histories.

2 changed files with 10 additions and 26 deletions

View File

@ -8,14 +8,6 @@ class Virtual extends Field {
public bool $readonly = true;
public function __construct(
public null|string|array $method = null,
public ? \Closure $closure = null,
) {
$this->method ??= [ static::class, 'noop' ];
}
public static function noop() : null
{
return null;
}
public ? string $method = null,
) {}
}

View File

@ -78,19 +78,11 @@ class RelationBuilder
protected function resolveVirtual(string $name) : mixed
{
if (null !== ($virtual = $this->resolver->searchFieldAnnotation($name, [ Attribute\Property\Virtual::class, Annotation\Property\Virtual::class ]))) {
try {
$arguments = [ $this->entity ];
if ($virtual->closure ?? false) {
return call_user_func_array($virtual->closure, $arguments);
}
elseif ($virtual->method ?? false) {
return call_user_func_array(is_array($virtual->method) ? $virtual->method : [$this->entity, $virtual->method], $arguments);
}
}
catch(\Throwable $e) {
throw new $e(sprintf("An error occurred while calling method from your #[Virtual] attribute in entity '%s::%s'.", $this->entity::class, $name ));
return call_user_func_array($virtual->closure, [ $this->entity ]);
}
return call_user_func_array([ $this->entity, $virtual->method ], [ $this->entity ]);
}
return false;