MockAliasManager.php in Drupal 9
File
core/modules/system/src/Tests/Routing/MockAliasManager.php
View source
<?php
namespace Drupal\system\Tests\Routing;
use Drupal\path_alias\AliasManagerInterface;
class MockAliasManager implements AliasManagerInterface {
protected $aliases = [];
protected $systemPaths = [];
protected $lookedUp = [];
public $defaultLanguage = 'en';
public function addAlias($path, $alias, $path_language = NULL) {
$language = $path_language ?: $this->defaultLanguage;
if ($path[0] !== '/') {
throw new \InvalidArgumentException('The path needs to start with a slash.');
}
if ($alias[0] !== '/') {
throw new \InvalidArgumentException('The alias needs to start with a slash.');
}
$this->aliases[$path][$language] = $alias;
$this->systemPaths[$alias][$language] = $path;
}
public function getPathByAlias($alias, $langcode = NULL) {
$langcode = $langcode ?: $this->defaultLanguage;
return $this->systemPaths[$alias][$langcode];
}
public function getAliasByPath($path, $langcode = NULL) {
if ($path[0] !== '/') {
throw new \InvalidArgumentException(sprintf('Source path %s has to start with a slash.', $path));
}
$langcode = $langcode ?: $this->defaultLanguage;
$this->lookedUp[$path] = 1;
return $this->aliases[$path][$langcode];
}
public function cacheClear($source = NULL) {
}
}