/**
  * @covers \Nia\RequestResponse\Cli\CliRequest::getPath
  */
 public function testGetPath()
 {
     $this->assertSame('/my/path.txt', $this->request->getPath());
     $stream = fopen('php://temp', 'r+');
     fwrite($stream, 'foobar');
     rewind($stream);
     // test without path
     $request = new CliRequest(['--foo=bar', '--bar=foo'], $stream);
     $this->assertSame('/', $request->getPath());
     fclose($stream);
 }
 /**
  *
  * {@inheritDoc}
  *
  * @see \Nia\Routing\Filter\FilterInterface::filterRequest($request, $context)
  */
 public function filterRequest(RequestInterface $request, WriteableMapInterface $context) : ResponseInterface
 {
     $matches = [];
     if (preg_match($this->regex, $request->getPath(), $matches)) {
         // extract only named matches.
         $data = array_intersect_key($matches, array_flip(array_filter(array_keys($matches), 'is_string')));
         foreach ($data as $name => $value) {
             $context->set($name, $value);
         }
     }
     throw new IgnoreFilterException();
 }
Example #3
0
 /**
  *
  * {@inheritDoc}
  *
  * @see \Nia\Routing\Condition\ConditionInterface::checkCondition($request, $context)
  */
 public function checkCondition(RequestInterface $request, MapInterface $context) : bool
 {
     return preg_match($this->regex, $request->getPath()) !== 0;
 }
Example #4
0
 /**
  *
  * {@inheritDoc}
  *
  * @see \Nia\Routing\Condition\ConditionInterface::checkCondition($request, $context)
  */
 public function checkCondition(RequestInterface $request, MapInterface $context) : bool
 {
     return $this->path === $request->getPath();
 }