Skip to content

Commit

Permalink
support attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Dec 19, 2023
1 parent f50341f commit 31de918
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,19 @@ function reflectionToParameters(ReflectionFunction|ReflectionMethod $reflection)
{
$parameters = parameters();
foreach ($reflection->getParameters() as $parameter) {
$reflectionParameter = new ReflectionParameterTyped($parameter);
try {
$push = reflectedParameterAttribute($parameter->getName(), $parameter);
} catch (LogicException) {
$push = (new ReflectionParameterTyped($parameter));
}
$callable = match ($parameter->isOptional()) {
true => 'withOptional',
default => 'withRequired',
};

$parameters = $parameters->{$callable}(
$parameter->getName(),
$reflectionParameter->parameter()
$push->parameter()
);
}

Expand Down Expand Up @@ -288,9 +292,8 @@ function reflectionToReturnParameter(ReflectionFunction|ReflectionMethod $reflec
function reflectedParameterAttribute(
string $parameter,
ReflectionParameter $reflection,
?string $type = null,
): ParameterAttributeInterface {
$attributes = $reflection->getAttributes($type);
$attributes = $reflection->getAttributes(ParameterAttributeInterface::class, ReflectionAttribute::IS_INSTANCEOF);
foreach ($attributes as $attribute) {
$attribute = $attribute->newInstance();

Expand Down

0 comments on commit 31de918

Please sign in to comment.