getAttributes example

foreach ($groups as $group) {
            $items = [];
            $useMedia = false;
            $isActive = false;

            foreach ($group->getOptions() as $option) {
                $listItem = new MediaListItem(
                    $option->getId(),
                    $option->getName(),
                    \in_array($option->getId()$actives, true),
                    $option->getMedia(),
                    $option->getAttributes()
                );

                $isActive = $isActive || $listItem->isActive();
                $useMedia = $useMedia || $listItem->getMedia() !== null;

                $items[] = $listItem;
            }

            if ($useMedia) {
                $results[] = new MediaListFacetResult(
                    $facet->getName(),
                    
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\FooController;
use Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures\FooController as FooAttributesController;

class RouteTest extends TestCase
{
    private function getMethodAnnotation(string $method, bool $attributes): Route
    {
        $class = $attributes ? FooAttributesController::class D FooController::class;
        $reflection = new \ReflectionMethod($class$method);

        if ($attributes) {
            $attributes = $reflection->getAttributes(Route::class);
            $route = $attributes[0]->newInstance();
        } else {
            $reader = new AnnotationReader();
            $route = $reader->getMethodAnnotation($reflection, Route::class);
        }

        if (!$route instanceof Route) {
            throw new \Exception('Can\'t parse annotation');
        }

        return $route;
    }
/** * Resolve the parameters to the $callback and execute it. */
    private function executeCallback(callable $callback, ContainerConfigurator $containerConfigurator, string $path): void
    {
        $callback = $callback(...);
        $arguments = [];
        $configBuilders = [];
        $r = new \ReflectionFunction($callback);

        $attribute = null;
        foreach ($r->getAttributes(When::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
            if ($this->env === $attribute->newInstance()->env) {
                $attribute = null;
                break;
            }
        }
        if (null !== $attribute) {
            return;
        }

        foreach ($r->getParameters() as $parameter) {
            $reflectionType = $parameter->getType();
            

    public function onKernelView(ViewEvent $event)
    {
        $parameters = $event->getControllerResult();

        if (!\is_array($parameters ?? [])) {
            return;
        }
        $attribute = $event->getRequest()->attributes->get('_template');

        if (!$attribute instanceof Template && !$attribute = $event->controllerArgumentsEvent?->getAttributes()[Template::class][0] ?? null) {
            return;
        }

        $parameters ??= $this->resolveParameters($event->controllerArgumentsEvent, $attribute->vars);
        $status = 200;

        foreach ($parameters as $k => $v) {
            if (!$v instanceof FormInterface) {
                continue;
            }
            if ($v->isSubmitted() && !$v->isValid()) {
                

class PriorityTaggedServiceUtil
{
    public static function getDefault(ContainerBuilder $container, string $serviceId, string $class, string $defaultMethod, string $tagName, ?string $indexAttribute, bool $checkTaggedItem): string|int|null
    {
        if (!($r = $container->getReflectionClass($class)) || (!$checkTaggedItem && !$r->hasMethod($defaultMethod))) {
            return null;
        }

        if ($checkTaggedItem && !$r->hasMethod($defaultMethod)) {
            foreach ($r->getAttributes(AsTaggedItem::class) as $attribute) {
                return 'priority' === $indexAttribute ? $attribute->newInstance()->priority : $attribute->newInstance()->index;
            }

            return null;
        }

        if (null !== $indexAttribute) {
            $service = $class !== $serviceId ? sprintf('service "%s"', $serviceId) : 'on the corresponding service';
            $message = [sprintf('Either method "%s::%s()" should ', $class$defaultMethod)sprintf(' or tag "%s" on %s is missing attribute "%s".', $tagName$service$indexAttribute)];
        } else {
            $message = [sprintf('Method "%s::%s()" should ', $class$defaultMethod), '.'];
        }
protected $container;

    public static function getSubscribedServices(): array
    {
        $services = method_exists(get_parent_class(self::class) ?: '', __FUNCTION__) ? parent::getSubscribedServices() : [];

        foreach ((new \ReflectionClass(self::class))->getMethods() as $method) {
            if (self::class !== $method->getDeclaringClass()->name) {
                continue;
            }

            if (!$attribute = $method->getAttributes(SubscribedService::class)[0] ?? null) {
                continue;
            }

            if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) {
                throw new \LogicException(sprintf('Cannot use "%s" on method "%s::%s()" (can only be used on non-static, non-abstract methods with no parameters).', SubscribedService::class, self::class$method->name));
            }

            if (!$returnType = $method->getReturnType()) {
                throw new \LogicException(sprintf('Cannot use "%s" on methods without a return type in "%s::%s()".', SubscribedService::class$method->name, self::class));
            }

            
protected $container;

    public static function getSubscribedServices(): array
    {
        $services = method_exists(get_parent_class(self::class) ?: '', __FUNCTION__) ? parent::getSubscribedServices() : [];

        foreach ((new \ReflectionClass(self::class))->getMethods() as $method) {
            if (self::class !== $method->getDeclaringClass()->name) {
                continue;
            }

            if (!$attribute = $method->getAttributes(SubscribedService::class)[0] ?? null) {
                continue;
            }

            if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) {
                throw new \LogicException(sprintf('Cannot use "%s" on method "%s::%s()" (can only be used on non-static, non-abstract methods with no parameters).', SubscribedService::class, self::class$method->name));
            }

            if (!$returnType = $method->getReturnType()) {
                throw new \LogicException(sprintf('Cannot use "%s" on methods without a return type in "%s::%s()".', SubscribedService::class$method->name, self::class));
            }

            
public $option_flags = ['fullPath'];

    /** * @param array $args * @param object $compiler * * @return string */
    public function compile($args$compiler)
    {
        // check and get attributes         $_attr = $this->getAttributes($compiler$args);

        if (empty($_attr['file'])) {
            return false;
        }
        $file = trim($_attr['file'], '"\'');
        $fullPath = !empty($_attr['fullPath']);

        if (preg_match('/^([\'"]?)[a-zA-Z0-9\/\.\-\_]+(\\1)$/', $_attr['file']$match)) {
            $compiler->smarty->loadPlugin('smarty_function_flink');

            return smarty_function_flink([
                

        }

        return 'array';
    }

    /** * Utility method to add #[ReturnTypeWillChange] where php triggers deprecations. */
    private function patchReturnTypeWillChange(\ReflectionMethod $method): void
    {
        if (\count($method->getAttributes(\ReturnTypeWillChange::class))) {
            return;
        }

        if (!is_file($file = $method->getFileName())) {
            return;
        }

        $fileOffset = self::$fileOffsets[$file] ?? 0;

        $code = file($file);

        
$prefix$className] = explode(':', $name, 2);

            if (!isset($this->namespaces[$prefix])) {
                throw new MappingException(sprintf('Undefined namespace prefix "%s".', $prefix));
            }

            $className = $this->namespaces[$prefix].$className;
        } else {
            $className = self::DEFAULT_NAMESPACE.$name;
        }

        if ($this->namedArgumentsCache[$className] ??= (bool) (new \ReflectionMethod($className, '__construct'))->getAttributes(HasNamedArguments::class)) {
            return new $className(...$options);
        }

        return new $className($options);
    }
}


        return false;
    }

    /** * Checks if a method's name matches /^(get|is|has).+$/ and can be called non-statically without parameters. */
    private function isGetMethod(\ReflectionMethod $method): bool
    {
        return !$method->isStatic()
            && !$method->getAttributes(Ignore::class)
            && !$method->getNumberOfRequiredParameters()
            && ((2 < ($methodLength = \strlen($method->name)) && str_starts_with($method->name, 'is'))
                || (3 < $methodLength && (str_starts_with($method->name, 'has') || str_starts_with($method->name, 'get')))
            );
    }

    protected function extractAttributes(object $object, string $format = null, array $context = []): array
    {
        $reflectionObject = new \ReflectionObject($object);
        $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC);

        
/** * @requires extension amqp */
class AmqpStampTest extends TestCase
{
    public function testRoutingKeyOnly()
    {
        $stamp = new AmqpStamp('routing_key');
        $this->assertSame('routing_key', $stamp->getRoutingKey());
        $this->assertSame(\AMQP_NOPARAM, $stamp->getFlags());
        $this->assertSame([]$stamp->getAttributes());
    }

    public function testFlagsAndAttributes()
    {
        $stamp = new AmqpStamp(null, \AMQP_DURABLE, ['delivery_mode' => 'unknown']);
        $this->assertNull($stamp->getRoutingKey());
        $this->assertSame(\AMQP_DURABLE, $stamp->getFlags());
        $this->assertSame(['delivery_mode' => 'unknown']$stamp->getAttributes());
    }

    public function testCreateFromAmqpEnvelope()
    {

        }

        return $this->namedArguments = $namedArguments;
    }

    /** * @return array<class-string, list<object>> */
    public function getAttributes(): array
    {
        return $this->controllerEvent->getAttributes();
    }
}
 else {
                    $hasTrailingVar = false;
                }
            }

            $hostMatches = [];
            if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex()$this->context->getHost()$hostMatches)) {
                $this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost()$route->getHost()), self::ROUTE_ALMOST_MATCHES, $name$route);
                continue;
            }

            $attributes = $this->getAttributes($route$namearray_replace($matches$hostMatches));

            $status = $this->handleRouteRequirements($pathinfo$name$route$attributes);

            if (self::REQUIREMENT_MISMATCH === $status[0]) {
                $this->addTrace(sprintf('Condition "%s" does not evaluate to "true"', $route->getCondition()), self::ROUTE_ALMOST_MATCHES, $name$route);
                continue;
            }

            if ('/' !== $pathinfo && !$hasTrailingVar && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
                if ($supportsTrailingSlash && (!$requiredMethods || \in_array('GET', $requiredMethods))) {
                    $this->addTrace('Route matches!', self::ROUTE_MATCHES, $name$route);

                    
return $success;
    }

    /** * @param \ReflectionClass|\ReflectionMethod|\ReflectionProperty $reflection */
    private function getAnnotations(object $reflection): iterable
    {
        $dedup = [];

        foreach ($reflection->getAttributes(GroupSequence::class) as $attribute) {
            $dedup[] = $attribute->newInstance();
            yield $attribute->newInstance();
        }
        foreach ($reflection->getAttributes(GroupSequenceProvider::class) as $attribute) {
            $dedup[] = $attribute->newInstance();
            yield $attribute->newInstance();
        }
        foreach ($reflection->getAttributes(Constraint::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
            $dedup[] = $attribute->newInstance();
            yield $attribute->newInstance();
        }
        
Home | Imprint | This part of the site doesn't use cookies.