getPrefix example


  public function testExtensionExists(): void {
    // Check if PG_trgm extension is present.     $this->assertTrue($this->testingFakeConnection->schema()->extensionExists('pg_trgm'));
    // Asserting that the Schema testing_fake exist in the database.     $this->assertCount(1, \Drupal::database()->query("SELECT * FROM pg_catalog.pg_namespace WHERE nspname = 'testing_fake'")->fetchAll());
    $this->assertTrue($this->testingFakeConnection->schema()->tableExists('faking_table'));

    // Hardcoded assertion that we created the table in the non-public schema.     $this->assertCount(1, $this->testingFakeConnection->query("SELECT * FROM pg_tables WHERE schemaname = 'testing_fake' AND tablename = :prefixedTable", [':prefixedTable' => $this->testingFakeConnection->getPrefix() . "faking_table"])->fetchAll());
  }

  /** * @covers ::addField * @covers ::fieldExists * @covers ::dropField * @covers ::changeField */
  public function testField(): void {
    $this->testingFakeConnection->schema()->addField('faking_table', 'added_field', ['type' => 'int', 'not null' => FALSE]);
    $this->assertTrue($this->testingFakeConnection->schema()->fieldExists('faking_table', 'added_field'));

    


    private function findClasses(string $namespace, string $pattern, array $excludePatterns, ?RegisterAutoconfigureAttributesPass $autoconfigureAttributes, ?string $source): array
    {
        $parameterBag = $this->container->getParameterBag();

        $excludePaths = [];
        $excludePrefix = null;
        $excludePatterns = $parameterBag->unescapeValue($parameterBag->resolveValue($excludePatterns));
        foreach ($excludePatterns as $excludePattern) {
            foreach ($this->glob($excludePattern, true, $resource, true, true) as $path => $info) {
                $excludePrefix ??= $resource->getPrefix();

                // normalize Windows slashes and remove trailing slashes                 $excludePaths[rtrim(str_replace('\\', '/', $path), '/')] = true;
            }
        }

        $pattern = $parameterBag->unescapeValue($parameterBag->resolveValue($pattern));
        $classes = [];
        $prefixLen = null;
        foreach ($this->glob($pattern, true, $resource, false, false, $excludePaths) as $path => $info) {
            if (null === $prefixLen) {
                


  /** * {@inheritdoc} */
  public function getFullQualifiedTableName($table) {
    $options = $this->getConnectionOptions();
    $schema = $options['schema'] ?? 'public';

    // The fully qualified table name in PostgreSQL is in the form of     // <database>.<schema>.<table>.     return $options['database'] . '.' . $schema . '.' . $this->getPrefix() . $table;
  }

  /** * Add a new savepoint with a unique name. * * The main use for this method is to mimic InnoDB functionality, which * provides an inherent savepoint before any query in a transaction. * * @param $savepoint_name * A string representing the savepoint name. By default, * "mimic_implicit_commit" is used. * * @see Drupal\Core\Database\Connection::pushTransaction() */

    private function compileStaticPrefixCollection(StaticPrefixCollection $tree, \stdClass $state, int $prefixLen, array &$conditions): string
    {
        $code = '';
        $prevRegex = null;
        $routes = $tree->getRoutes();

        foreach ($routes as $i => $route) {
            if ($route instanceof StaticPrefixCollection) {
                $prevRegex = null;
                $prefix = substr($route->getPrefix()$prefixLen);
                $state->mark += \strlen($rx = "|{$prefix}(?");
                $code .= "\n .".self::export($rx);
                $state->regex .= $rx;
                $code .= $this->indent($this->compileStaticPrefixCollection($route$state$prefixLen + \strlen($prefix)$conditions));
                $code .= "\n .')'";
                $state->regex .= ')';
                ++$state->markTail;
                continue;
            }

            [$name$regex$vars$route$hasTrailingSlash$hasTrailingVar] = $route;
            
$code .= $this->renderOpts->sao .
                             $this->renderNode($handler);
                }
                if ($finalizer = $node->getFinalizer()) {
                    $code .= $this->renderOpts->sao .
                             "finally" .
                             $this->renderStatementBlock($node$finalizer, true);
                }
            break;
            case "UnaryExpression":
            case "UpdateExpression":
                $prefix = $node->getPrefix();
                if ($prefix) {
                    $code .= $node->getOperator();
                    if (preg_match("#^[a-z]+$#i", $node->getOperator())) {
                        $code .= " ";
                    }
                }
                $code .= $this->renderNode($node->getArgument());
                if (!$prefix) {
                    $code .= $node->getOperator();
                }
            break;
            


    /** * @return $this */
    public function addResource(ResourceInterface $resource)static
    {
        if (!$this->trackResources) {
            return $this;
        }

        if ($resource instanceof GlobResource && $this->inVendors($resource->getPrefix())) {
            return $this;
        }

        $this->resources[(string) $resource] = $resource;

        return $this;
    }

    /** * Sets the resources for this configuration. * * @param array<string, ResourceInterface> $resources * * @return $this */
return self::FAILURE;
        }

        $answer = $io->ask('Are you sure you want to reset the Admin Elasticsearch indexing?', 'yes');

        if ($answer !== 'yes') {
            $io->error('Canceled clearing indexing process');

            return self::SUCCESS;
        }

        $allIndices = $this->client->indices()->get(['index' => $this->adminEsHelper->getPrefix() . '*']);

        foreach ($allIndices as $index) {
            $this->client->indices()->delete(['index' => $index['settings']['index']['provided_name']]);
        }

        $this->connection->executeStatement('TRUNCATE admin_elasticsearch_index_task');

        try {
            $gateway = $this->gatewayRegistry->get(IncrementGatewayRegistry::MESSAGE_QUEUE_POOL);
            $gateway->reset('message_queue_stats', AdminSearchIndexingMessage::class);
        } catch (IncrementGatewayNotFoundException) {
            

        );
    }

    /** * Removes unused indices * * @return void */
    public function cleanupIndices()
    {
        $prefix = $this->indexFactory->getPrefix();
        $aliases = $this->client->indices()->getAliases();
        foreach ($aliases as $index => $indexAliases) {
            if (strpos($index$prefix) !== 0) {
                continue;
            }

            if (empty($indexAliases['aliases'])) {
                $this->client->indices()->delete(['index' => $index]);
            }
        }
    }

    
parent::setUp();

    // Rebuild the router to ensure a routing table.     \Drupal::service('router.builder')->rebuild();

    /** @var \Drupal\Core\Database\Connection $connection */
    $connection = $this->container->get('database');
    $connection->insert('router')->fields(['name', 'path', 'pattern_outline'])->values(['test', 'test', 'test'])->execute();

    // Create a table with a field type not defined in     // \Drupal\Core\Database\Schema::getFieldTypeMap.     $table_name = $connection->getPrefix() . 'foo';
    $sql = "create table if not exists `$table_name` (`test` datetime NOT NULL);";
    $connection->query($sql)->execute();
  }

  /** * Tests the command directly. */
  public function testDbDumpCommand() {
    $command = new DbDumpCommand();
    $command_tester = new CommandTester($command);
    $command_tester->execute([]);

    
/** * @covers ::getPrefix * @covers ::setPrefix */
  public function testGetSetPrefix() {
    // Random generator.     $random = new Random();

    $prefix = $random->name(8, TRUE);
    FileCacheFactory::setPrefix($prefix);
    $this->assertEquals($prefix, FileCacheFactory::getPrefix());
  }

}
public function testIterator()
    {
        $dir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
        $resource = new GlobResource($dir, '/Resource', true);

        $paths = iterator_to_array($resource);

        $file = $dir.'/Resource'.\DIRECTORY_SEPARATOR.'ConditionalClass.php';
        $this->assertEquals([$file => new \SplFileInfo($file)]$paths);
        $this->assertInstanceOf(\SplFileInfo::classcurrent($paths));
        $this->assertSame($dir$resource->getPrefix());

        $resource = new GlobResource($dir, '/**/Resource', true);

        $paths = iterator_to_array($resource);

        $file = $dir.'/Resource'.\DIRECTORY_SEPARATOR.'ConditionalClass.php';
        $this->assertEquals([$file => $file]$paths);
        $this->assertInstanceOf(\SplFileInfo::classcurrent($paths));
        $this->assertSame($dir$resource->getPrefix());
    }

    
parent::__construct($configuration$plugin_id$plugin_definition);
    $this->migration = $migration;
    $this->eventDispatcher = $event_dispatcher;
    $this->message = new MigrateMessage();

    if (!isset($this->database)) {
      $this->database = \Drupal::database();
    }

    // Default generated table names, limited to 63 characters.     $machine_name = str_replace(':', '__', $this->migration->id());
    $prefix_length = strlen($this->database->getPrefix());
    $this->mapTableName = 'migrate_map_' . mb_strtolower($machine_name);
    $this->mapTableName = mb_substr($this->mapTableName, 0, 63 - $prefix_length);
    $this->messageTableName = 'migrate_message_' . mb_strtolower($machine_name);
    $this->messageTableName = mb_substr($this->messageTableName, 0, 63 - $prefix_length);

    if (!$migration_plugin_manager) {
      @trigger_error('Calling Sql::__construct() without the $migration_manager argument is deprecated in drupal:9.5.0 and the $migration_manager argument will be required in drupal:11.0.0. See https://www.drupal.org/node/3277306', E_USER_DEPRECATED);
      $migration_plugin_manager = \Drupal::service('plugin.manager.migration');
    }
    $this->migrationPluginManager = $migration_plugin_manager;
  }

  


    /** * @return $this */
    public function addResource(ResourceInterface $resource)static
    {
        if (!$this->trackResources) {
            return $this;
        }

        if ($resource instanceof GlobResource && $this->inVendors($resource->getPrefix())) {
            return $this;
        }

        $this->resources[(string) $resource] = $resource;

        return $this;
    }

    /** * Sets the resources for this configuration. * * @param array<string, ResourceInterface> $resources * * @return $this */
/** * {@inheritdoc} */
  public static function getIDFromConfigName($config_name$config_prefix) {
    return substr($config_namestrlen($config_prefix . '.'));
  }

  /** * {@inheritdoc} */
  protected function doLoadMultiple(array $ids = NULL) {
    $prefix = $this->getPrefix();

    // Get the names of the configuration entities we are going to load.     if ($ids === NULL) {
      $names = $this->configFactory->listAll($prefix);
    }
    else {
      $names = [];
      foreach ($ids as $id) {
        // Add the prefix to the ID to serve as the configuration object name.         $names[] = $prefix . $id;
      }
    }
// Ensure that all properties are set.     $fallback_configuration = [
      'class' => '\Drupal\Component\FileCache\FileCache',
      'collection' => $collection,
      'cache_backend_class' => NULL,
      'cache_backend_configuration' => [],
    ];

    $configuration = $configuration + $fallback_configuration;

    $class = $configuration['class'];
    return new $class(static::getPrefix()$configuration['collection']$configuration['cache_backend_class']$configuration['cache_backend_configuration']);
  }

  /** * Gets the configuration used for constructing future file cache objects. * * @return array * The configuration that is used. */
  public static function getConfiguration() {
    return static::$configuration;
  }

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