public static function Securepages::matchPath in Secure Pages 8
Match path against securepages settings.
Parameters
string $path: Path to match against settings.
Return value
bool|NULL
- FALSE: Path should be non-secure.
- TRUE: Path should be secure.
- NULL: No explicit information.
3 calls to Securepages::matchPath()
- FormBuilder::buildFormAction in src/
FormBuilder.php - Builds the $form['#action'].
- Securepages::matchCurrentPath in src/
Securepages.php - Match the current path against the configured settings.
- SecurepagesTest::_testMatch in src/
Tests/ SecurepagesTest.php - Tests the securepages_match() function.
File
- src/
Securepages.php, line 95 - Contains \Drupal\securepages\Securepages.
Class
- Securepages
- Utility class for global functionality.
Namespace
Drupal\securepagesCode
public static function matchPath($path) {
// Convert paths to lowercase. This allows comparison of the same path
// with different case. Ex: /Page, /page, /PAGE.
$config = \Drupal::config('securepages.settings');
$pages = Unicode::strtolower(implode("\n", $config
->get('pages')));
$ignore = Unicode::strtolower(implode("\n", $config
->get('ignore')));
$request = \Drupal::requestStack()
->getCurrentRequest();
/** @var \Drupal\Core\Path\AliasManager $alias_manager */
$alias_manager = \Drupal::service('path.alias_manager');
/** @var \Drupal\Core\Path\PathMatcher $path_matcher */
$path_matcher = \Drupal::service('path.matcher');
// Compare the lowercase path alias (if any) and internal path.
$path = rtrim($path, '/');
$path_alias = Unicode::strtolower($alias_manager
->getAliasByPath($path));
// Checks to see if the page matches the current settings.
if ($ignore) {
if ($path_matcher
->matchPath($path_alias, $ignore) || $path != $path_alias && $path_matcher
->matchPath($path, $ignore)) {
//Securepages::log('Ignored path (Path: "@path", Line: @line, Pattern: "@pattern")', $path, $ignore);
return $request
->isSecure();
}
}
if ($pages) {
$result = $path_matcher
->matchPath($path_alias, $pages) || $path != $path_alias && $path_matcher
->matchPath($path, $pages);
if (!($config
->get('secure') xor $result)) {
//Securepages::log('Secure path (Path: "@path", Line: @line, Pattern: "@pattern")', $path, $pages);
}
return !($config
->get('secure') xor $result);
}
else {
return NULL;
}
}