ReflectionClass example


class PhpRequirementsTest extends UnitTestCase {

  /** * Ensures that PHP EOL dates are valid. * * This ensures that that all of the PHP EOL Date items are valid ISO 8601 * dates and are keyed by a valid version number. */
  public function testPhpEolDates(): void {
    $reflected = new \ReflectionClass(PhpRequirements::class);
    $php_eol_dates = $reflected->getStaticPropertyValue('phpEolDates');

    foreach ($php_eol_dates as $version => $eol_date) {
      // Ensure that all of the version numbers are defined in a superset of       // semver: 'major.minor.patch-modifier', where (unlike in semver) all       // parts but the major are optional.       // @see version_compare()       $this->assertMatchesRegularExpression('/^([0-9]+)(\.([0-9]+)(\.([0-9]+)(-[A-Za-z0-9]+)?)?)?$/', $version);

      // Ensure that all of the EOL dates are defined using ISO 8601 format.       $this->assertMatchesRegularExpression('/^([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])$/', $eol_date);
    }
new EventDispatcher(),
            $this->createMock(AbstractCacheTracer::class),
            new HttpCacheKeyGenerator('test', new EventDispatcher()[]),
            $this->createMock(MaintenanceModeResolver::class),
            []
        );

        $store->lock($request);

        static::assertTrue($item->get());

        $reflectionClass = new \ReflectionClass($item);
        $prop = $reflectionClass->getProperty('expiry');
        $prop->setAccessible(true);

        static::assertEqualsWithDelta(time() + 3, $prop->getValue($item), 1);
    }
}
return null;
        }

        if (!isset($extends[Collection::class])) {
            return null;
        }

        if (isset($extends[EntitySearchResult::class])) {
            return null;
        }

        $filePath = (new \ReflectionClass($className))->getFileName();
        if ($filePath === false) {
            return null;
        }

        $stmts = $this->parseFile($filePath);
        $findNodes = (new NodeFinder())->findInstanceOf($stmts, ClassMethod::class);

        /** @var ClassMethod $findNode */
        foreach ($findNodes as $findNode) {
            if ((string) $findNode->name === 'getExpectedClass') {
                $nodeStmts = $findNode->stmts;
                
/** * Loads from annotations from a class. * * @throws \InvalidArgumentException When route can't be parsed */
    public function load(mixed $class, string $type = null): RouteCollection
    {
        if (!class_exists($class)) {
            throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
        }

        $class = new \ReflectionClass($class);
        if ($class->isAbstract()) {
            throw new \InvalidArgumentException(sprintf('Annotations from class "%s" cannot be read as it is abstract.', $class->getName()));
        }

        $this->hasDeprecatedAnnotations = false;

        try {
            $globals = $this->getGlobals($class);
            $collection = new RouteCollection();
            $collection->addResource(new FileResource($class->getFileName()));
            if ($globals['env'] && $this->env !== $globals['env']) {
                

#[AsCommand(name: 'server:dump', description: 'Start a dump server that collects and displays dumps in a single place')] class ServerDumpPlaceholderCommand extends Command
{
    private ServerDumpCommand $replacedCommand;

    public function __construct(DumpServer $server = null, array $descriptors = [])
    {
        $this->replacedCommand = new ServerDumpCommand((new \ReflectionClass(DumpServer::class))->newInstanceWithoutConstructor()$descriptors);

        parent::__construct();
    }

    protected function configure(): void
    {
        $this->setDefinition($this->replacedCommand->getDefinition());
        $this->setHelp($this->replacedCommand->getHelp());
        $this->setDescription($this->replacedCommand->getDescription());
    }

    
/** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    // Make sure the install API is available.     include_once DRUPAL_ROOT . '/core/includes/install.inc';

    $driver = $form_state->getValue('driver');
    $database = $form_state->getValue($driver);
    $drivers = drupal_get_database_types();
    $reflection = new \ReflectionClass($drivers[$driver]);
    $install_namespace = $reflection->getNamespaceName();
    // Cut the trailing \Install from namespace.     $database['namespace'] = substr($install_namespace, 0, strrpos($install_namespace, '\\'));
    $database['driver'] = $driver;
    // See default.settings.php for an explanation of the 'autoload' key.     if ($autoload = Database::findDriverAutoloadDirectory($database['namespace'], DRUPAL_ROOT)) {
      $database['autoload'] = $autoload;
    }

    $form_state->set('database', $database);
    foreach ($this->getDatabaseErrors($database$form_state->getValue('settings_file')) as $name => $message) {
      
foreach ($shopwareClasses as $class) {
            if (!class_exists($class)) {
                // skip not autoloadable test classes                 continue;
            }

            if (is_subclass_of($class, FunctionHook::class) || is_subclass_of($class, TraceHook::class)) {
                continue;
            }

            if (is_subclass_of($class, Hook::class) && !(new \ReflectionClass($class))->isAbstract()) {
                $hookClasses[] = $class;
            }
        }

        if (\count($hookClasses) === 0) {
            throw new \RuntimeException('No HookClasses found.');
        }

        sort($hookClasses);

        return $hookClasses;
    }

    protected function _match($deviceClass)
    {
        // Validate device class         $r = new ReflectionClass($deviceClass);
        if (!$r->implementsInterface('Zend_Http_UserAgent_Device')) {
            throw new Zend_Http_UserAgent_Exception(sprintf(
                'Invalid device class provided ("%s"); must implement Zend_Http_UserAgent_Device',
                $deviceClass
            ));
        }

        $userAgent = $this->getUserAgent();

        // Call match method on device class         return call_user_func(
            
self::$metadataParser->setIgnoreNotImportedAnnotations(true);
            self::$metadataParser->setIgnoredAnnotationNames($this->ignoredAnnotationNames);
            self::$metadataParser->setImports(array(
                'enum'          => 'Doctrine\Common\Annotations\Annotation\Enum',
                'target'        => 'Doctrine\Common\Annotations\Annotation\Target',
                'attribute'     => 'Doctrine\Common\Annotations\Annotation\Attribute',
                'attributes'    => 'Doctrine\Common\Annotations\Annotation\Attributes'
            ));
        }

        $class      = new \ReflectionClass($name);
        $docComment = $class->getDocComment();

        // Sets default values for annotation metadata         $metadata = array(
            'default_property' => null,
            'has_constructor'  => (null !== $constructor = $class->getConstructor()) && $constructor->getNumberOfParameters() > 0,
            'properties'       => array(),
            'property_types'   => array(),
            'attribute_types'  => array(),
            'targets_literal'  => null,
            'targets'          => Target::TARGET_ALL,
            


    private function registerCustomFieldsMapping(): void
    {
        $eventDispatcher = $this->getContainer()->get('event_dispatcher');

        $this->addEventListener($eventDispatcher, ElasticsearchProductCustomFieldsMappingEvent::classfunction DElasticsearchProductCustomFieldsMappingEvent $event): void {
            $event->setMapping('evolvesTo', CustomFieldTypes::TEXT);
        });

        $definition = $this->getContainer()->get(ElasticsearchProductDefinition::class);
        $class = new \ReflectionClass($definition);
        $reflectionProperty = $class->getProperty('customFieldsTypes');
        $reflectionProperty->setAccessible(true);
        $reflectionProperty->setValue($definition, null);

        if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            $definition = $this->getContainer()->get(EsProductDefinition::class);
            $class = new \ReflectionClass($definition);
            $reflectionProperty = $class->getProperty('customFieldsTypes');
            $reflectionProperty->setAccessible(true);
            $reflectionProperty->setValue($definition, null);
        }
    }
/** * Builds a proxy class string. * * @param string $class_name * The class name of the actual service. * * @return string * The full string with namespace class and methods. */
  public function build($class_name) {
    $reflection = new \ReflectionClass($class_name);

    $proxy_class_name = $this->buildProxyClassName($class_name);
    $proxy_namespace = $this->buildProxyNamespace($class_name);
    $proxy_class_shortname = str_replace($proxy_namespace . '\\', '', $proxy_class_name);

    $output = '';
    $class_documentation = <<<'EOS' namespace {{ namespace }}{ /** * Provides a proxy class for \{{ class_name }}. * * @see \Drupal\Component\ProxyBuilder */

    private array $rootDirs;

    protected function setUp(): void
    {
        $this->rootDirs = array_filter(array_map(static function Dstring $class): ?string {
            if (!\class_exists($class)) {
                return null;
            }

            return \dirname((string) (new \ReflectionClass($class))->getFileName());
        }, self::ROOT_CLASSES));
    }

    public function testSourceFilesForUnvalidatedPrivileges(): void
    {
        $additionalPermission = $this->getAdditionalPermissions();

        if (empty($additionalPermission)) {
            return;
        }

        

  public static function getTestInfo($classname$doc_comment = NULL) {
    if ($doc_comment === NULL) {
      $reflection = new \ReflectionClass($classname);
      $doc_comment = $reflection->getDocComment();
    }
    $info = [
      'name' => $classname,
    ];
    $annotations = [];
    // Look for annotations, allow an arbitrary amount of spaces before the     // * but nothing else.     preg_match_all('/^[ ]*\* \@([^\s]*) (.*$)/m', $doc_comment$matches);
    if (isset($matches[1])) {
      foreach ($matches[1] as $key => $annotation) {
        


  /** * Asserts that expected view properties have been unset by destroy(). * * @param \Drupal\views\ViewExecutable $view * The view executable. * * @internal */
  protected function assertViewDestroy(ViewExecutable $view): void {
    $reflection = new \ReflectionClass($view);
    $defaults = $reflection->getDefaultProperties();
    // The storage and user should remain.     unset(
      $defaults['storage'],
      $defaults['user'],
      $defaults['request'],
      $defaults['routeProvider'],
      $defaults['viewsData']
    );

    foreach ($defaults as $property => $default) {
      
$backoff = new TimeBackoff('test', [
            [
                'limit' => 3,
                'interval' => '10 seconds',
            ],
            [
                'limit' => 5,
                'interval' => '30 seconds',
            ],
        ]);

        $reflection = new \ReflectionClass($backoff);
        $stringLimits = $reflection->getProperty('stringLimits');
        $stringLimits->setAccessible(true);
        $stringLimits->setValue($backoff, 'invalid');

        static::expectException(\BadMethodCallException::class);
        $backoff->__wakeup();
    }
}
Home | Imprint | This part of the site doesn't use cookies.