newInstance example


                } catch (Zend_Exception $ze) {
                    continue;
                }
            }

            $class = new ReflectionClass($className);
            if ($class->implementsInterface('Zend_Filter_Interface')) {
                if ($class->hasMethod('__construct')) {
                    $object = $class->newInstanceArgs($args);
                } else {
                    $object = $class->newInstance();
                }
                return $object->filter($value);
            }
        }
        throw new Zend_Filter_Exception("Filter class not found from basename '$classBaseName'");
    }
}
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();
        }
        if (!$this->reader) {
            
$class = $container->getReflectionClass($class);

        if (!$class) {
            return null;
        }

        if (!$class->implementsInterface(ConfigurationInterface::class)) {
            throw new LogicException(sprintf('The extension configuration class "%s" must implement "%s".', $class->getName(), ConfigurationInterface::class));
        }

        if (!($constructor = $class->getConstructor()) || !$constructor->getNumberOfRequiredParameters()) {
            return $class->newInstance();
        }

        return null;
    }

    final protected function processConfiguration(ConfigurationInterface $configuration, array $configs): array
    {
        $processor = new Processor();

        return $this->processedConfigs[] = $processor->processConfiguration($configuration$configs);
    }

    

            break;
        }

        // There's no specific status code defined in the configuration for this exception         if (!$throwable instanceof HttpExceptionInterface) {
            $class = new \ReflectionClass($throwable);

            do {
                if ($attributes = $class->getAttributes(WithHttpStatus::class, \ReflectionAttribute::IS_INSTANCEOF)) {
                    /** @var WithHttpStatus $instance */
                    $instance = $attributes[0]->newInstance();

                    $throwable = new HttpException($instance->statusCode, $throwable->getMessage()$throwable$instance->headers);
                    $event->setThrowable($throwable);
                    break;
                }
            } while ($class = $class->getParentClass());
        }

        $e = FlattenException::createFromThrowable($throwable);

        $this->logException($throwablesprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass()$e->getMessage()$e->getFile()$e->getLine())$logLevel);
    }

        }

        return $success;
    }

    private function getAnnotations(\ReflectionMethod|\ReflectionClass|\ReflectionProperty $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();
        }
        if (!$this->reader) {
            
final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
{
    public function createArgumentMetadata(string|object|array $controller, \ReflectionFunctionAbstract $reflector = null): array
    {
        $arguments = [];
        $reflector ??= new \ReflectionFunction($controller(...));

        foreach ($reflector->getParameters() as $param) {
            $attributes = [];
            foreach ($param->getAttributes() as $reflectionAttribute) {
                if (class_exists($reflectionAttribute->getName())) {
                    $attributes[] = $reflectionAttribute->newInstance();
                }
            }

            $arguments[] = new ArgumentMetadata($param->getName()$this->getType($param)$param->isVariadic()$param->isDefaultValueAvailable()$param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull()$attributes);
        }

        return $arguments;
    }

    /** * Returns an associated type to the given parameter if available. */

        $class = self::getClassName($class);
        if (isset(self::$instances[$class])) {
            return self::$instances[$class];
        }

        $rc = new ReflectionClass($class);

        if (isset($args)) {
            $instance = $rc->newInstanceArgs($args);
        } else {
            $instance = $rc->newInstance();
        }

        return $instance;
    }

    /** * Reset the instance of the given class. */
    public static function resetInstance($class = null)
    {
        $class = self::getClassName($class);
        


    /** * @return array */
    protected function getGlobals(\ReflectionClass $class)
    {
        $globals = $this->resetGlobals();

        $annot = null;
        if ($attribute = $class->getAttributes($this->routeAnnotationClass, \ReflectionAttribute::IS_INSTANCEOF)[0] ?? null) {
            $annot = $attribute->newInstance();
        }
        if (!$annot && $this->reader) {
            $annot = $this->reader->getClassAnnotation($class$this->routeAnnotationClass);
        }

        if ($annot) {
            if (null !== $annot->getName()) {
                $globals['name'] = $annot->getName();
            }

            if (null !== $annot->getPath()) {
                
return lcfirst(str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $this->name))));
    }

    public static function parseName(\ReflectionParameter $parameter, self &$attribute = null): string
    {
        $attribute = null;
        if (!$target = $parameter->getAttributes(self::class)[0] ?? null) {
            return $parameter->name;
        }

        $attribute = $target->newInstance();
        $name = $attribute->name ??= $parameter->name;
        $parsedName = $attribute->getParsedName();

        if (!preg_match('/^[a-zA-Z_\x7f-\xff]/', $parsedName)) {
            if (($function = $parameter->getDeclaringFunction()) instanceof \ReflectionMethod) {
                $function = $function->class.'::'.$function->name;
            } else {
                $function = $function->name;
            }

            throw new InvalidArgumentException(sprintf('Invalid #[Target] name "%s" on parameter "$%s" of "%s()": the first character must be a letter.', $name$parameter->name, $function));
        }
return $loaded;
    }

    /** * @param \ReflectionClass|\ReflectionMethod|\ReflectionProperty $reflector */
    public function loadAnnotations(object $reflector): iterable
    {
        foreach ($reflector->getAttributes() as $attribute) {
            if ($this->isKnownAttribute($attribute->getName())) {
                try {
                    yield $attribute->newInstance();
                } catch (\Error $e) {
                    if (\Error::class !== $e::class) {
                        throw $e;
                    }
                    $on = match (true) {
                        $reflector instanceof \ReflectionClass => ' on class '.$reflector->name,
                        $reflector instanceof \ReflectionMethod => sprintf(' on "%s::%s()"', $reflector->getDeclaringClass()->name, $reflector->name),
                        $reflector instanceof \ReflectionProperty => sprintf(' on "%s::$%s"', $reflector->getDeclaringClass()->name, $reflector->name),
                        default => '',
                    };

                    
// do not attempt to register enum typed arguments if not already present in bindings                         continue;
                    } elseif (!$p->allowsNull()) {
                        $invalidBehavior = ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE;
                    }

                    if (Request::class === $type || SessionInterface::class === $type || Response::class === $type) {
                        continue;
                    }

                    if ($autowireAttributes) {
                        $attribute = $autowireAttributes[0]->newInstance();
                        $value = $parameterBag->resolveValue($attribute->value);

                        if ($attribute instanceof AutowireCallable) {
                            $value = $attribute->buildDefinition($value$type$p);
                        }

                        if ($value instanceof Reference) {
                            $args[$p->name] = $type ? new TypedReference($value$type$invalidBehavior$p->name) : new Reference($value$invalidBehavior);
                        } else {
                            $args[$p->name] = new Reference('.value.'.$container->hash($value));
                            $container->register((string) $args[$p->name], 'mixed')
                                


    /** * @return array<string, mixed> */
    protected function getGlobals(\ReflectionClass $class)
    {
        $globals = $this->resetGlobals();

        $annot = null;
        if ($attribute = $class->getAttributes($this->routeAnnotationClass, \ReflectionAttribute::IS_INSTANCEOF)[0] ?? null) {
            $annot = $attribute->newInstance();
        }
        if (!$annot && $annot = $this->reader?->getClassAnnotation($class$this->routeAnnotationClass)) {
            $this->hasDeprecatedAnnotations = true;
        }

        if ($annot) {
            if (null !== $annot->getName()) {
                $globals['name'] = $annot->getName();
            }

            if (null !== $annot->getPath()) {
                

    public static function getHandledMessages(): iterable
    {
        $reflection = new \ReflectionClass(static::class);
        $attributes = $reflection->getAttributes(AsMessageHandler::class);

        $messageClasses = [];
        foreach ($attributes as $attribute) {
            /** @var AsMessageHandler $messageAttribute */
            $messageAttribute = $attribute->newInstance();
            $messageClasses[] = $messageAttribute->handles;
        }

        return array_filter($messageClasses);
    }

    abstract public function run(): void;

    protected function markTaskRunning(ScheduledTask $task): void
    {
        $this->scheduledTaskRepository->update([
            [


        if ($secure) {
            $this->verifyClass(
                $reflectionClass,
                $docPath,
                $directories
            );
        }

        if (!$reflectionClass->getConstructor()) {
            return $reflectionClass->newInstance();
        }

        $constructorParams = $reflectionClass->getConstructor()->getParameters();

        $newParams = [];
        foreach ($constructorParams as $constructorParam) {
            $paramName = $constructorParam->getName();

            if (!isset($arguments[$paramName])) {
                if (!$constructorParam->isOptional()) {
                    throw new RuntimeException(sprintf('Required constructor parameter missing: "$%s".', $paramName));
                }
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;
    }

    
Home | Imprint | This part of the site doesn't use cookies.