You are here

class PathPrefixMethod in Persistent URL 8

Plugin annotation


@PurlMethod(
    id="path_prefix"
)

Hierarchy

Expanded class hierarchy of PathPrefixMethod

File

src/Plugin/Purl/Method/PathPrefixMethod.php, line 14

Namespace

Drupal\purl\Plugin\Purl\Method
View source
class PathPrefixMethod implements MethodInterface, RequestAlteringInterface {
  public function contains(Request $request, $modifier) {
    $uri = $request
      ->getRequestUri();
    return $this
      ->pathContains($modifier, $uri);
  }
  private function pathContains($modifier, $path) {
    return strpos($path, '/' . $modifier) === 0;
  }
  public function alterRequest(Request $request, $identifier) {
    $uri = $request
      ->getRequestUri();
    $newPath = substr($uri, strlen($identifier) + 1);
    $request->server
      ->set('REQUEST_URI', $newPath);
  }
  public function enterContext($modifier, $path, array &$options) {
    return '/' . $modifier . $path;
  }
  public function exitContext($modifier, $path, array &$options) {
    if (!$this
      ->pathContains($modifier, $path)) {
      return null;
    }
    return substr($path, 0, strlen($modifier) + 1);
  }

}

Members