preg_grep example

// Find out what migrate map tables have rows for the node migrations.       // It is either the classic, 'dN_node', or the complete,       // 'dN_node_complete', or both. This is used to determine which migrations       // are run and if migrations using the node migrations in a       // migration_lookup are altered.       $bases = ['node', 'node_complete'];
      $tables = $connection->schema()
        ->findTables('migrate_map_d' . $version . '_node%');
      foreach ($bases as $base) {
        $has_rows = $base . '_has_rows';
        $base_tables = preg_grep('/^migrate_map_d' . $version . '_' . $base . '_{2}.*$/', $tables);
        // Set the has_rows True when a map table has rows with a positive         // count for the matched migration.         foreach ($base_tables as $base_table) {
          if ($connection->schema()->tableExists($base_table)) {
            $count = $connection->select($base_table)->countQuery()
              ->execute()->fetchField();
            if ($count > 0) {
              $$has_rows = TRUE;
              break;
            }
          }
        }
      // will become an empty string when we remove the prefix, which will       // probably surprise the caller, besides not being a prefixed table. So       // remove it.       if (!empty($unprefixed_table_name)) {
        $tables[$unprefixed_table_name] = $unprefixed_table_name;
      }
    }

    // Convert the table expression from its SQL LIKE syntax to a regular     // expression and escape the delimiter that will be used for matching.     $table_expression = str_replace(['%', '_']['.*?', '.']preg_quote($table_expression, '/'));
    $tables = preg_grep('/^' . $table_expression . '$/i', $tables);

    return $tables;
  }

  /** * Check if a column exists in the given table. * * @param string $table * The name of the table in drupal (no prefixing). * @param string $column * The name of the column. * * @return bool * TRUE if the given column exists, otherwise FALSE. */
return array_intersect($matches[1]array_keys($data));
    }

    /** * Checks to see if an error exists for the given field. */
    public function hasError(string $field): bool
    {
        $pattern = '/^' . str_replace('\.\*', '\..+', preg_quote($field, '/')) . '$/';

        return (bool) preg_grep($patternarray_keys($this->getErrors()));
    }

    /** * Returns the error(s) for a specified $field (or empty string if not * set). */
    public function getError(?string $field = null): string
    {
        if ($field === null && count($this->rules) === 1) {
            $field = array_key_first($this->rules);
        }

        

  public function getPrefixGroupedUserFunctions($prefixes = []) {
    $functions = get_defined_functions();

    // If a list of prefixes is supplied, trim down the list to those items     // only as efficiently as possible.     if ($prefixes) {
      $theme_functions = preg_grep('/^(' . implode(')|(', $prefixes) . ')_/', $functions['user']);
    }
    else {
      $theme_functions = $functions['user'];
    }

    $grouped_functions = [];
    // Splitting user defined functions into groups by the first prefix.     foreach ($theme_functions as $function) {
      [$first_prefix] = explode('_', $function, 2);
      $grouped_functions[$first_prefix][] = $function;
    }

    


    /** * Finds a registered namespace by a name or an abbreviation. * * @throws NamespaceNotFoundException When namespace is incorrect or ambiguous */
    public function findNamespace(string $namespace): string
    {
        $allNamespaces = $this->getNamespaces();
        $expr = implode('[^:]*:', array_map('preg_quote', explode(':', $namespace))).'[^:]*';
        $namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);

        if (empty($namespaces)) {
            $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);

            if ($alternatives = $this->findAlternatives($namespace$allNamespaces)) {
                if (1 == \count($alternatives)) {
                    $message .= "\n\nDid you mean this?\n ";
                } else {
                    $message .= "\n\nDid you mean one of these?\n ";
                }

                
// Forbidden attributes not containing wildcards, such as `style`.       if (!self::isWildcardAttributeName($forbidden_attribute_name)) {
        if (array_key_exists($forbidden_attribute_name$attribute_restrictions)) {
          $this->context->buildViolation($constraint->message)
            ->setParameter('%dangerous_tag', $value)
            ->addViolation();
        }
      }
      // Forbidden attributes containing wildcards such as `on*`.       else {
        $regex = self::getRegExForWildCardAttributeName($forbidden_attribute_name);
        if (!empty(preg_grep($regexarray_keys($attribute_restrictions)))) {
          $this->context->buildViolation($constraint->message)
            ->setParameter('%dangerous_tag', $value)
            ->addViolation();
        }
      }
    }
  }

  /** * Checks whether the given attribute name contains a wildcard, e.g. `data-*`. * * @param string $attribute_name * The attribute name to check. * * @return bool * Whether the given attribute name contains a wildcard. */
$prev = $this->lexer->getPrevious();
        if ($prev->isA(EmailLexer::S_COLON)) {
            $this->warnings[IPV6ColonEnd::CODE] = new IPV6ColonEnd();
        }

        $IPv6       = substr($addressLiteral, 5);
        //Daniel Marschall's new IPv6 testing strategy         $matchesIP  = explode(':', $IPv6);
        $groupCount = count($matchesIP);
        $colons     = strpos($IPv6, '::');

        if (count(preg_grep('/^[0-9A-Fa-f]{0,4}$/', $matchesIP, PREG_GREP_INVERT)) !== 0) {
            $this->warnings[IPV6BadChar::CODE] = new IPV6BadChar();
        }

        if ($colons === false) {
            // We need exactly the right number of groups             if ($groupCount !== $maxGroups) {
                $this->warnings[IPV6GroupCount::CODE] = new IPV6GroupCount();
            }
            return;
        }

        
foreach ($constraint->entityTypes as $entity_type_id) {
      $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);

      if (!$entity_type instanceof ConfigEntityTypeInterface) {
        throw new LogicException("'$entity_type_id' is not a config entity type.");
      }

      // Ensure the current entity type's config prefix is found in the config       // dependencies of the entity being validated.       $pattern = sprintf('/^%s\\.\\w+/', $entity_type->getConfigPrefix());
      if (!preg_grep($pattern$config_dependencies)) {
        $this->context->addViolation($constraint->message, [
          '@entity_type' => $entity->getEntityType()->getSingularLabel(),
          '@dependency_type' => $entity_type->getSingularLabel(),
        ]);
      }
    }
  }

}
parent::setUp();
    $this->pluginManager = $this->container->get('plugin.manager.migration');
    $this->pluginManager->createInstance('d6_user');
  }

  /** * Tests that dummy map tables do not exist. */
  public function testNoDummyTables() {
    $database = \Drupal::database();
    $tables = $database->schema()->findTables('%migrate_map%');
    $dummy_tables = preg_grep("/.*migrate_map_([0-9a-fA-F]){13}/", $tables);
    $this->assertCount(0, $dummy_tables);
  }

}

  public function findAllClassFiles($extension = NULL) {
    $classmap = [];
    $namespaces = $this->registerTestNamespaces();
    if (isset($extension)) {
      // Include tests in the \Drupal\Tests\{$extension} namespace.       $pattern = "/Drupal\\\(Tests\\\)?$extension\\\/";
      $namespaces = array_intersect_key($namespacesarray_flip(preg_grep($patternarray_keys($namespaces))));
    }
    foreach ($namespaces as $namespace => $paths) {
      foreach ($paths as $path) {
        if (!is_dir($path)) {
          continue;
        }
        $classmap += static::scanDirectory($namespace$path);
      }
    }
    return $classmap;
  }

  
      // will become an empty string when we remove the prefix, which will       // probably surprise the caller, besides not being a prefixed table. So       // remove it.       if (!empty($unprefixed_table_name)) {
        $tables[$unprefixed_table_name] = $unprefixed_table_name;
      }
    }

    // Convert the table expression from its SQL LIKE syntax to a regular     // expression and escape the delimiter that will be used for matching.     $table_expression = str_replace(['%', '_']['.*?', '.']preg_quote($table_expression, '/'));
    $tables = preg_grep('/^' . $table_expression . '$/i', $tables);

    return $tables;
  }

  /** * {@inheritdoc} */
  public function renameTable($table$new_name) {
    if (!$this->tableExists($table)) {
      throw new SchemaObjectDoesNotExistException("Cannot rename '$table' to '$new_name': table '$table' doesn't exist.");
    }
    
/** * Returns an array of table names * * @return array|false * * @throws DatabaseException */
    public function listTables(bool $constrainByPrefix = false)
    {
        if (isset($this->dataCache['table_names']) && $this->dataCache['table_names']) {
            return $constrainByPrefix
                ? preg_grep("/^{$this->DBPrefix}/", $this->dataCache['table_names'])
                : $this->dataCache['table_names'];
        }

        $sql = $this->_listTables($constrainByPrefix);

        if ($sql === false) {
            if ($this->DBDebug) {
                throw new DatabaseException('This feature is not available for the database you are using.');
            }

            return false;
        }

  protected function nodeMigrateMapTableCount($version) {
    $results = [];
    $bases = ['node', 'node_complete'];
    $tables = \Drupal::database()->schema()
      ->findTables('migrate_map_d' . $version . '_node%');

    foreach ($bases as $base) {
      $base_tables = preg_grep('/^migrate_map_d' . $version . '_' . $base . '_{2}.*$/', $tables);
      $results[$base] = count($base_tables);
    }
    return $results;
  }

  /** * Remove the node migrate map table. * * @param string $type * The type of node migration, 'complete' or 'classic'. * @param string $version * The source database version. * * @throws \Exception */

    return $migrations ? $this->createInstances(array_keys($migrations)) : [];
  }

  /** * {@inheritdoc} */
  public function expandPluginIds(array $migration_ids) {
    $plugin_ids = [];
    $all_ids = array_keys($this->getDefinitions());
    foreach ($migration_ids as $id) {
      $plugin_ids += preg_grep('/^' . preg_quote($id, '/') . PluginBase::DERIVATIVE_SEPARATOR . '/', $all_ids);
      if ($this->hasDefinition($id)) {
        $plugin_ids[] = $id;
      }
    }
    return $plugin_ids;
  }

  /** * {@inheritdoc} */
  public function buildDependencyMigration(array $migrations, array $dynamic_ids) {
    
$this->assertTrue(defined('APPPATH'));
    }

    public function testBaseUrlHasBeenSet()
    {
        $validation = Services::validation();

        $env = false;

        // Check the baseURL in .env         if (is_file(HOMEPATH . '.env')) {
            $env = preg_grep('/^app\.baseURL = ./', file(HOMEPATH . '.env')) !== false;
        }

        if ($env) {
            // BaseURL in .env is a valid URL?             // phpunit.xml.dist sets app.baseURL in $_SERVER             // So if you set app.baseURL in .env, it takes precedence             $config = new App();
            $this->assertTrue(
                $validation->check($config->baseURL, 'valid_url'),
                'baseURL "' . $config->baseURL . '" in .env is not valid URL'
            );
        }
Home | Imprint | This part of the site doesn't use cookies.