コード例 #1
0
 /**
  * @inheritdoc
  */
 public function isMatched(RequestContext $requestContext)
 {
     if (!preg_match('!^/my/!', $requestContext->getPath())) {
         return false;
     }
     $requestContext->setPath(preg_replace('!^/my!', '', $requestContext->getPath()));
 }
コード例 #2
0
 public function testRequestContext()
 {
     $requestContext = new RequestContext('GET', 'example.com', 'http', '/', 'a=1&b=2');
     $this->assertEquals('example.com', $requestContext->getHost());
     $requestContext->setHost('www.example.com');
     $this->assertEquals('www.example.com', $requestContext->getHost());
     $this->assertEquals('get', $requestContext->getMethod());
     $requestContext->setMethod('post');
     $this->assertEquals('post', $requestContext->getMethod());
     $this->assertEquals('/', $requestContext->getPath());
     $requestContext->setPath('/index/');
     $this->assertEquals('http', $requestContext->getScheme());
     $requestContext->setScheme('https');
     $this->assertEquals('https', $requestContext->getScheme());
     $this->assertTrue($requestContext->hasParameter('a'));
     $this->assertEquals(1, $requestContext->getParameter('a'));
     $this->assertEquals(2, $requestContext->getParameter('b'));
     $this->assertEquals(['a' => 1, 'b' => 2], $requestContext->getParameters());
     $this->assertNull($requestContext->getParameter('c'));
     $requestContext->setParameter('c', 3);
     $this->assertEquals(3, $requestContext->getParameter('c'));
     $this->assertEquals('a=1&b=2&c=3', $requestContext->getQueryString());
     $requestContext->setParameter('c', 4)->removeParameter('a')->setParameter('b', 5);
     $this->assertNull($requestContext->getParameter('a'));
     $this->assertEquals('b=5&c=4', $requestContext->getQueryString());
     $this->assertEquals(['b' => 5, 'c' => 4], $requestContext->getParameters());
     $requestContext->setParameters(['a' => 1, 'b' => 2]);
     $this->assertEquals(['a' => 1, 'b' => 2], $requestContext->getParameters());
     $this->assertEquals('a=1&b=2', $requestContext->getQueryString());
 }
コード例 #3
0
 /**
  * @param RequestContext $requestContext
  *
  * @return bool
  */
 public function isMatched(RequestContext $requestContext)
 {
     if (!empty($this->languagesIds)) {
         if (preg_match('!^/(' . implode('|', $this->languagesIds) . ')(/.*)$!', $requestContext->getPath(), $match)) {
             $this->storeDefaultParameter('lang', $match[1]);
             $newPath = $match[2];
             if (empty($newPath)) {
                 $newPath = '/';
             }
             $requestContext->setPath($newPath);
         } else {
             $this->storeDefaultParameter('lang', $this->defaultLanguage);
         }
     }
     return true;
 }
コード例 #4
0
ファイル: PrefixModifier.php プロジェクト: shakhraj/reroute
 /**
  * @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 true;
     }
     return false;
 }