How get attributes of function into this function?

  Kiến thức lập trình

When i get the attributes of my function. If i getName(), i’ve a path as name BaseServiceClientfilters .. How i can only get filters as name ?

#[filters(['email', 'emailVerified', 'enabled', 'firstName', 'lastName', 'q', 'username'])]
public function getUsers(?array $filter = null): iterable
{
    $method = new ReflectionMethod($this, 'getUsers');
    $attributes = $method->getAttributes();

    $f = [];
    foreach ($attributes as $reflection) {
        $f[$reflection->getName()] =  $reflection->getArguments();
    }

    dd($f);

OUPUT:

[
    'BaseServiceClientfilters' => [ /** I'ld filter, like thats i can $method->getAttributes('filters)
        (int) 0 => [
            (int) 0 => 'email',
            (int) 1 => 'emailVerified',
            (int) 2 => 'enabled',
            (int) 3 => 'firstName',
            (int) 4 => 'lastName',
            (int) 5 => 'q',
            (int) 6 => 'username',
        ],
    ],
]

New contributor

Maël BOUTEMY is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT