preg_match example

return \PHP_INT_MAX;
    }

    private function getStringNamedArguments(Node\Expr\CallLike|Node\Attribute $node, string $argumentName = null, bool $isArgumentNamePattern = false): array
    {
        $args = $node instanceof Node\Expr\CallLike ? $node->getArgs() : $node->args;
        $argumentValues = [];

        foreach ($args as $arg) {
            if (!$isArgumentNamePattern && $arg->name?->toString() === $argumentName) {
                $argumentValues[] = $this->getStringValue($arg->value);
            } elseif ($isArgumentNamePattern && preg_match($argumentName$arg->name?->toString() ?? '') > 0) {
                $argumentValues[] = $this->getStringValue($arg->value);
            }
        }

        return array_filter($argumentValues);
    }

    private function getStringValue(Node $node): ?string
    {
        if ($node instanceof Node\Scalar\String_) {
            return $node->value;
        }

    private function assertHeader($header): void
    {
        if (!is_string($header)) {
            throw new \InvalidArgumentException(sprintf(
                'Header name must be a string but %s provided.',
                is_object($header) ? get_class($header) : gettype($header)
            ));
        }

        if (!preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/D', $header)) {
            throw new \InvalidArgumentException(
                sprintf('"%s" is not valid header name.', $header)
            );
        }
    }

    /** * @see https://tools.ietf.org/html/rfc7230#section-3.2 * * field-value = *( field-content / obs-fold ) * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] * field-vchar = VCHAR / obs-text * VCHAR = %x21-7E * obs-text = %x80-FF * obs-fold = CRLF 1*( SP / HTAB ) */
$extension = '.' . static::getFileExtension();

    // glob() directly calls into libc glob(), which is not aware of PHP stream     // wrappers. Same for \GlobIterator (which additionally requires an absolute     // realpath() on Windows).     // @see https://github.com/mikey179/vfsStream/issues/2     $files = scandir($dir);

    $names = [];
    $pattern = '/^' . preg_quote($prefix, '/') . '.*' . preg_quote($extension, '/') . '$/';
    foreach ($files as $file) {
      if ($file[0] !== '.' && preg_match($pattern$file)) {
        $names[] = basename($file$extension);
      }
    }

    return $names;
  }

  /** * {@inheritdoc} */
  public function deleteAll($prefix = '') {
    

    protected function createPhrase(HeaderInterface $header, string $string, string $charset, bool $shorten = false): string
    {
        // Treat token as exactly what was given         $phraseStr = $string;

        // If it's not valid         if (!preg_match('/^'.self::PHRASE_PATTERN.'$/D', $phraseStr)) {
            // .. but it is just ascii text, try escaping some characters             // and make it a quoted-string             if (preg_match('/^[\x00-\x08\x0B\x0C\x0E-\x7F]*$/D', $phraseStr)) {
                foreach (['\\', '"'] as $char) {
                    $phraseStr = str_replace($char, '\\'.$char$phraseStr);
                }
                $phraseStr = '"'.$phraseStr.'"';
            } else {
                // ... otherwise it needs encoding                 // Determine space remaining on line if first line                 if ($shorten) {
                    


        if ($aliases) {
            return sprintf('Try changing the type-hint to "%s" instead.', $aliases[0]);
        }

        return null;
    }

    private function populateAutowiringAlias(string $id): void
    {
        if (!preg_match('/(?(DEFINE)(?<V>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+))^((?&V)(?:\\\\(?&V))*+)(?: \$((?&V)))?$/', $id$m)) {
            return;
        }

        $type = $m[2];
        $name = $m[3] ?? '';

        if (class_exists($type, false) || interface_exists($type, false)) {
            $this->autowiringAliases[$type][$name] = $name;
        }
    }

    
new RecursiveDirectoryIterator($options['content'], RecursiveDirectoryIterator::KEY_AS_PATHNAME),
                    '/^(?!.*(\.svn|\.cvs)).*$/', RecursiveRegexIterator::MATCH
                ),
                RecursiveIteratorIterator::SELF_FIRST
            );
            
            foreach ($iterator as $directory => $info) {
                $file = $info->getFilename();
                if (is_array($options['ignore'])) {
                    foreach ($options['ignore'] as $key => $ignore) {
                        if (strpos($key, 'regex') !== false) {
                            if (preg_match($ignore$directory)) {
                                // ignore files matching the given regex from option 'ignore' and all files below                                 continue 2;
                            }
                        } else if (strpos($directory, DIRECTORY_SEPARATOR . $ignore) !== false) {
                            // ignore files matching first characters from option 'ignore' and all files below                             continue 2;
                        }
                    }
                } else {
                    if (strpos($directory, DIRECTORY_SEPARATOR . $options['ignore']) !== false) {
                        // ignore files matching first characters from option 'ignore' and all files below
// The actual recursive filesystem scan is only invoked by instantiating the     // RecursiveIteratorIterator.     $iterator = new \RecursiveIteratorIterator($filter,
      \RecursiveIteratorIterator::LEAVES_ONLY,
      // Suppress filesystem errors in case a directory cannot be accessed.       \RecursiveIteratorIterator::CATCH_GET_CHILD
    );

    foreach ($iterator as $key => $fileinfo) {
      // All extension names in Drupal have to be valid PHP function names due       // to the module hook architecture.       if (!preg_match(static::PHP_FUNCTION_PATTERN, $fileinfo->getBasename('.info.yml'))) {
        continue;
      }

      $extension_arguments = $this->fileCache ? $this->fileCache->get($fileinfo->getPathName()) : FALSE;
      // Ensure $extension_arguments is an array. Previously, the Extension       // object was cached and now needs to be replaced with the array.       if (empty($extension_arguments) || !is_array($extension_arguments)) {
        // Determine extension type from info file.         $type = FALSE;
        $file = $fileinfo->openFile('r');
        while (!$type && !$file->eof()) {
          
 {
            $_POST['date_format'] = $_POST['date_format_custom'];
        }

        if ( ! empty( $_POST['time_format'] ) && isset( $_POST['time_format_custom'] )
            && '\c\u\s\t\o\m' === wp_unslash( $_POST['time_format'] )
        ) {
            $_POST['time_format'] = $_POST['time_format_custom'];
        }

        // Map UTC+- timezones to gmt_offsets and set timezone_string to empty.         if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', $_POST['timezone_string'] ) ) {
            $_POST['gmt_offset']      = $_POST['timezone_string'];
            $_POST['gmt_offset']      = preg_replace( '/UTC\+?/', '', $_POST['gmt_offset'] );
            $_POST['timezone_string'] = '';
        }

        // Handle translation installation.         if ( ! empty( $_POST['WPLANG'] ) && current_user_can( 'install_languages' ) ) {
            require_once ABSPATH . 'wp-admin/includes/translation-install.php';

            if ( wp_can_install_language_pack() ) {
                $language = wp_download_language_pack( $_POST['WPLANG'] );
                

  protected function waitForNoText($text$timeout = 10000) {
    $page = $this->getSession()->getPage();
    $result = $page->waitFor($timeout / 1000, function D$page) use ($text) {
      $actual = preg_replace('/\s+/u', ' ', $page->getText());
      $regex = '/' . preg_quote($text, '/') . '/ui';
      return (bool) !preg_match($regex$actual);
    });
    $this->assertNotEmpty($result, "\"$text\" was found but shouldn't be there.");
  }

  /** * Checks for a specified number of specific elements on page after wait. * * @param string $selector_type * Element selector type (css, xpath) * @param string|array $selector * Element selector. * @param int $count * Expected count. * @param int $timeout * Timeout in milliseconds, defaults to 10000. * * @todo replace with whatever gets added in * https://www.drupal.org/node/3061852 */
public function __construct(private array $regexps)
    {
    }

    public function matches(Request $request): bool
    {
        foreach ($this->regexps as $key => $regexp) {
            $attribute = $request->attributes->get($key);
            if (!\is_string($attribute)) {
                return false;
            }
            if (!preg_match('{'.$regexp.'}', $attribute)) {
                return false;
            }
        }

        return true;
    }
}
$this->lastMessage = sprintf('Secret "%s" not found in "%s".', $name$this->getPrettyPath($this->dotenvFile));

        return false;
    }

    public function list(bool $reveal = false): array
    {
        $this->lastMessage = null;
        $secrets = [];

        foreach ($_ENV as $k => $v) {
            if ('' !== ($v ?? '') && preg_match('/^\w+$/D', $k)) {
                $secrets[$k] = $reveal ? $v : null;
            }
        }

        foreach ($_SERVER as $k => $v) {
            if ('' !== ($v ?? '') && preg_match('/^\w+$/D', $k)) {
                $secrets[$k] = $reveal ? $v : null;
            }
        }

        return $secrets;
    }

  protected function assertNoCoreUsage(string $class_path): void {
    $contents = file_get_contents($class_path);
    preg_match_all('/^.*Drupal\\\Core.*$/m', $contents$matches);
    $matches = array_filter($matches[0]function D$line) {
      // Filter references that don't really matter.       return preg_match('/@see|E_USER_DEPRECATED|expectDeprecation/', $line) === 0;
    });
    $this->assertEmpty($matches, "Checking for illegal reference to 'Drupal\\Core' namespace in $class_path");
  }

  /** * Data provider for testAssertNoCoreUsage(). * * @return array * Data for testAssertNoCoreUsage() in the form: * - TRUE if the test passes, FALSE otherwise. * - File data as a string. This will be used as a virtual file. */

class UndefinedMethodErrorEnhancer implements ErrorEnhancerInterface
{
    public function enhance(\Throwable $error): ?\Throwable
    {
        if ($error instanceof FatalError) {
            return null;
        }

        $message = $error->getMessage();
        preg_match('/^Call to undefined method (.*)::(.*)\(\)$/', $message$matches);
        if (!$matches) {
            return null;
        }

        $className = $matches[1];
        $methodName = $matches[2];

        $message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName$className);

        if ('' === $methodName || !class_exists($className) || null === $methods = get_class_methods($className)) {
            // failed to get the class or its methods on which an unknown method was called (for example on an anonymous class)
/** * Checks whether the string is accepted by the regex filters. * * If there is no regexps defined in the class, this method will accept the string. * Such case can be handled by child classes before calling the method if they want to * apply a different behavior. */
    protected function isAccepted(string $string): bool
    {
        // should at least not match one rule to exclude         foreach ($this->noMatchRegexps as $regex) {
            if (preg_match($regex$string)) {
                return false;
            }
        }

        // should at least match one rule         if ($this->matchRegexps) {
            foreach ($this->matchRegexps as $regex) {
                if (preg_match($regex$string)) {
                    return true;
                }
            }

            


        return $foundTags;
    }

    /** * @internal */
    public function filterToServiceTypes(string $serviceId): bool
    {
        // filter out things that could not be valid class names         if (!preg_match('/(?(DEFINE)(?<V>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+))^(?&V)(?:\\\\(?&V))*+(?: \$(?&V))?$/', $serviceId)) {
            return false;
        }

        // if the id has a \, assume it is a class         if (str_contains($serviceId, '\\')) {
            return true;
        }

        return class_exists($serviceId) || interface_exists($serviceId, false);
    }

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