for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace ReRoute\Modifier;
/**
* @package ReRoute\Modifier
*/
class PrefixModifier extends AbstractRouteModifier {
* @var string
public $prefix;
* @param string $prefix
*
* @return PrefixModifier
public function setPrefix($prefix) {
$this->prefix = $prefix;
return $this;
}
* @return string
public function getPrefix() {
return $this->prefix;
* @inheritdoc
public function isMatched(\ReRoute\RequestContext $requestContext) {
$prefix = $this->getPrefix();
if (empty($prefix)) {
return true;
if (strpos($requestContext->getPath(), $prefix) === 0) {
$pathWithoutPrefix = (string) substr($requestContext->getPath(), strlen($prefix));
if (substr($pathWithoutPrefix, 0, 1) != '/') {
$pathWithoutPrefix = '/' . $pathWithoutPrefix;
$requestContext->setPath($pathWithoutPrefix);
return false;
public function build(\ReRoute\Url $url, \ReRoute\UrlBuilder $urlBuilder) {
if (!empty($prefix)) {
$url->setPath($this->getPrefix() . $url->getPath());