getNamespaceName example


  protected function prepareAnnotationDefinition(AnnotationInterface $annotation$class, BaseStaticReflectionParser $parser = NULL) {
    if (!($annotation instanceof MultipleProviderAnnotationInterface)) {
      throw new \LogicException('AnnotatedClassDiscoveryAutomatedProviders annotations must implement \Drupal\migrate\Annotation\MultipleProviderAnnotationInterface');
    }
    $annotation->setClass($class);
    $providers = $annotation->getProviders();
    // Loop through all the parent classes and add their providers (which we     // infer by parsing their namespaces) to the $providers array.     do {
      $providers[] = $this->getProviderFromNamespace($parser->getNamespaceName());
    } while ($parser = StaticReflectionParser::getParentParser($parser$this->finder));
    $providers = array_unique(array_filter($providersfunction D$provider) {
      return $provider && $provider !== 'component';
    }));
    $annotation->setProviders($providers);
  }

  /** * {@inheritdoc} */
  public function getDefinitions() {
    
return [$this->docBlockFactory->create($reflectionMethod$this->createFromReflector($reflector))$prefix];
        } catch (\InvalidArgumentException|\RuntimeException) {
            return null;
        }
    }

    /** * Prevents a lot of redundant calls to ContextFactory::createForNamespace(). */
    private function createFromReflector(\ReflectionClass $reflector): Context
    {
        $cacheKey = $reflector->getNamespaceName().':'.$reflector->getFileName();

        if (isset($this->contexts[$cacheKey])) {
            return $this->contexts[$cacheKey];
        }

        $this->contexts[$cacheKey] = $this->contextFactory->createFromReflector($reflector);

        return $this->contexts[$cacheKey];
    }
}
    public function getDocComment()
    {
        return $this->staticReflectionParser->getDocComment();
    }

    /** * {@inheritDoc} */
    #[\ReturnTypeWillChange]     public function getNamespaceName()
    {
        return $this->staticReflectionParser->getNamespaceName();
    }

    /** * @return string[] */
    public function getUseStatements()
    {
        return $this->staticReflectionParser->getUseStatements();
    }

    /** * {@inheritDoc} */
if ($source_connection) {
      $info = Database::getConnectionInfo($source_connection);
      $database = reset($info);
    }
    else {
      // Retrieve the database driver from the form, use reflection to get the       // namespace, and then construct a valid database array the same as in       // settings.php.       $driver = $form_state->getValue('driver');
      $drivers = $this->getDatabaseTypes();
      $reflection = new \ReflectionClass($drivers[$driver]);
      $install_namespace = $reflection->getNamespaceName();

      $database = $form_state->getValue($driver);
      // Cut the trailing \Install from namespace.       $database['namespace'] = substr($install_namespace, 0, strrpos($install_namespace, '\\'));
      $database['driver'] = $driver;

      // Validate the driver settings and just end here if we have any issues.       $connection = NULL;
      if ($errors = $drivers[$driver]->validateDatabaseSettings($database)) {
        foreach ($errors as $name => $message) {
          $this->errors[$name] = $message;
        }
$this->getNamespace($definition),
            $this->getClass($definition),
            $fields,
            $calls
        );
    }

    private function getNamespace(EntityDefinition $definition): string
    {
        $reflection = new \ReflectionClass($definition);

        return $reflection->getNamespaceName();
    }

    private function getClass(EntityDefinition $definition): string
    {
        $parts = explode('_', (string) $definition->getEntityName());

        $parts = array_map('ucfirst', $parts);

        return implode('', $parts) . 'Hydrator';
    }

    

  public function testMultipleStatements() {
    $this->expectException(\InvalidArgumentException::class);
    Database::getConnection('default', 'default')->prepareStatement('SELECT * FROM {test}; SELECT * FROM {test_people}', []);
  }

  /** * Tests that the method ::condition() returns a Condition object. */
  public function testCondition() {
    $connection = Database::getConnection('default', 'default');
    $namespace = (new \ReflectionObject($connection))->getNamespaceName() . "\\Condition";
    if (!class_exists($namespace)) {
      $namespace = Condition::class;
    }
    $condition = $connection->condition('AND');
    $this->assertSame($namespaceget_class($condition));
  }

  /** * Tests deprecation of ::getUnprefixedTablesMap(). * * @group legacy */


        if (false !== $parentClass = $reflection->getParentClass()) {
            $uses[] = $this->collectUses($parentClass);
        }

        return $uses ? array_merge(...$uses) : [];
    }

    private function extractFromFullClassName(\ReflectionClass $reflection): array
    {
        $namespace = trim($reflection->getNamespaceName(), '\\');
        $fileName = $reflection->getFileName();

        if (\is_string($fileName) && is_file($fileName)) {
            if (false === $contents = file_get_contents($fileName)) {
                throw new \RuntimeException(sprintf('Unable to read file "%s".', $fileName));
            }

            $factory = new ContextFactory();
            $context = $factory->createForNamespace($namespace$contents);

            return [$namespace$context->getNamespaceAliases()];
        }
public function __construct(object $connection, array $connection_options) {
    assert(count($this->identifierQuotes) === 2 && Inspector::assertAllStrings($this->identifierQuotes), '\Drupal\Core\Database\Connection::$identifierQuotes must contain 2 string values');

    // Manage the table prefix.     $connection_options['prefix'] = $connection_options['prefix'] ?? '';
    $this->setPrefix($connection_options['prefix']);

    // Work out the database driver namespace if none is provided. This normally     // written to setting.php by installer or set by     // \Drupal\Core\Database\Database::parseConnectionInfo().     if (empty($connection_options['namespace'])) {
      $connection_options['namespace'] = (new \ReflectionObject($this))->getNamespaceName();
    }

    $this->connection = $connection;
    $this->connectionOptions = $connection_options;
  }

  /** * Opens a client connection. * * @param array $connection_options * The database connection settings array. * * @return object * A client connection object. */


            foreach ($annotation->names as $annot) {
                $ignoredAnnotationNames[$annot] = true;
            }
        }

        $this->imports[$type][$name] = array_merge(
            self::$globalImports,
            $this->phpParser->parseUseStatements($reflection),
            [
                '__NAMESPACE__' => $reflection->getNamespaceName(),
                'self' => $name,
            ]
        );

        $this->ignoredAnnotationNames[$type][$name] = $ignoredAnnotationNames;
    }
}
/** * {@inheritdoc} */
  public function getDriverClass($class) {
    static $fixed_namespace;
    if (!$fixed_namespace) {
      // Override because we've altered the namespace in       // \Drupal\KernelTests\Core\Cache\EndOfTransactionQueriesTest::getDatabaseConnectionInfo()       // to use the logging Connection classes. Set to a proper database driver       // namespace.       $this->connectionOptions['namespace'] = (new \ReflectionClass(get_parent_class($this)))->getNamespaceName();
      $fixed_namespace = TRUE;
    }
    return parent::getDriverClass($class);
  }

  /** * Returns the executed queries. * * @return string[] */
  public function getLoggedStatements() {
    
/** * {@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) {
      $form_state->setErrorByName($name$message);
    }
if (!$bundleConfig['dir']) {
            if (\in_array($bundleConfig['type']['annotation', 'staticphp', 'attribute'])) {
                $bundleConfig['dir'] = $bundleClassDir.'/'.$this->getMappingObjectDefaultName();
            } else {
                $bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory($bundleDir);
            }
        } else {
            $bundleConfig['dir'] = $bundleDir.'/'.$bundleConfig['dir'];
        }

        if (!$bundleConfig['prefix']) {
            $bundleConfig['prefix'] = $bundle->getNamespaceName().'\\'.$this->getMappingObjectDefaultName();
        }

        return $bundleConfig;
    }

    /** * Register all the collected mapping information with the object manager by registering the appropriate mapping drivers. * * @return void */
    protected function registerMappingDrivers(array $objectManager, ContainerBuilder $container)
    {
if ($filename === false) {
            return [];
        }

        $content = $this->getFileContent($filename$reflection->getStartLine());

        if ($content === null) {
            return [];
        }

        $namespace = preg_quote($reflection->getNamespaceName());
        $content   = preg_replace('/^.*?(\bnamespace\s+' . $namespace . '\s*[;{].*)$/s', '\\1', $content);
        $tokenizer = new TokenParser('<?php ' . $content);

        return $tokenizer->parseUseStatements($reflection->getNamespaceName());
    }

    /** * Gets the content of the file right up to the given line number. * * @param string $filename The name of the file to load. * @param int $lineNumber The number of lines to read from file. * * @return string|null The content of the file or null if the file does not exist. */
Home | Imprint | This part of the site doesn't use cookies.