You are here

class PathMatcher in Acquia Lift Connector 8

Same name and namespace in other branches
  1. 8.4 src/Service/Helper/PathMatcher.php \Drupal\acquia_lift\Service\Helper\PathMatcher
  2. 8.3 src/Service/Helper/PathMatcher.php \Drupal\acquia_lift\Service\Helper\PathMatcher

Hierarchy

Expanded class hierarchy of PathMatcher

2 files declare their use of PathMatcher
PathContext.php in src/Service/Context/PathContext.php
Contains \Drupal\acquia_lift\Service\Context\PathContext.
PathMatcherTest.php in tests/src/Unit/Service/Helper/PathMatcherTest.php
Contains \Drupal\Tests\acquia_lift\Service\Helper\PathMatcherTest.
1 string reference to 'PathMatcher'
acquia_lift.services.yml in ./acquia_lift.services.yml
acquia_lift.services.yml
1 service uses PathMatcher
acquia_lift.service.helper.path_matcher in ./acquia_lift.services.yml
Drupal\acquia_lift\Service\Helper\PathMatcher

File

src/Service/Helper/PathMatcher.php, line 14
Contains \Drupal\acquia_lift\Service\Helper\PathMatcher.

Namespace

Drupal\acquia_lift\Service\Helper
View source
class PathMatcher {

  /**
   * Alias manager.
   *
   * @var \Drupal\Core\Path\AliasManagerInterface
   */
  private $aliasManager;

  /**
   * Path matcher.
   *
   * @var \Drupal\Core\Path\PathMatcherInterface
   */
  private $pathMatcher;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
   *   The alias manager service.
   * @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
   *   The path matcher service.
   */
  public function __construct(AliasManagerInterface $alias_manager, PathMatcherInterface $path_matcher) {
    $this->aliasManager = $alias_manager;
    $this->pathMatcher = $path_matcher;
  }

  /**
   * Determine if the path falls into one of the allowed paths (in terms of path patterns).
   *
   * @param string $path
   *   The actual path that's being matched by.
   * @param string $path_patterns
   *   The path patterns that the path is being matched to.
   *
   * @return boolean
   *   True if should attach.
   */
  public function match($path, $path_patterns) {

    // Convert path to lowercase and match.
    $converted_path = Unicode::strtolower($path);
    $converted_path_patterns = Unicode::strtolower($path_patterns);
    if ($this->pathMatcher
      ->matchPath($converted_path, $converted_path_patterns)) {
      return TRUE;
    }

    // Compare the lowercase path alias (if any) and internal path.
    $converted_path_alias = Unicode::strtolower($this->aliasManager
      ->getAliasByPath($converted_path));
    if ($converted_path != $converted_path_alias && $this->pathMatcher
      ->matchPath($converted_path_alias, $converted_path_patterns)) {
      return TRUE;
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PathMatcher::$aliasManager private property Alias manager.
PathMatcher::$pathMatcher private property Path matcher.
PathMatcher::match public function Determine if the path falls into one of the allowed paths (in terms of path patterns).
PathMatcher::__construct public function Constructor.