Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HeaderRequestMatcher.php

class HeaderRequestMatcher

Checks the presence of HTTP headers in a Request.

@author Alexandre Daubois <alex.daubois@gmail.com>

Hierarchy

  • class \Symfony\Component\HttpFoundation\RequestMatcher\HeaderRequestMatcher implements \Symfony\Component\HttpFoundation\RequestMatcherInterface

Expanded class hierarchy of HeaderRequestMatcher

File

vendor/symfony/http-foundation/RequestMatcher/HeaderRequestMatcher.php, line 22

Namespace

Symfony\Component\HttpFoundation\RequestMatcher
View source
class HeaderRequestMatcher implements RequestMatcherInterface {
    
    /**
     * @var string[]
     */
    private array $headers;
    
    /**
     * @param string[]|string $headers A header or a list of headers
     *                                 Strings can contain a comma-delimited list of headers
     */
    public function __construct(array|string $headers) {
        $this->headers = array_reduce((array) $headers, static fn(array $headers, string $header) => array_merge($headers, preg_split('/\\s*,\\s*/', $header)), []);
    }
    public function matches(Request $request) : bool {
        if (!$this->headers) {
            return true;
        }
        foreach ($this->headers as $header) {
            if (!$request->headers
                ->has($header)) {
                return false;
            }
        }
        return true;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
HeaderRequestMatcher::$headers private property
HeaderRequestMatcher::matches public function Decides whether the rule(s) implemented by the strategy matches the supplied request. Overrides RequestMatcherInterface::matches
HeaderRequestMatcher::__construct public function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal