/** * Constructor. * * @param string $name * @param mixed $subject * @param array $args */ public function __construct($name, $subject, array $args) { $this->name = $name; $this->subject = $subject; $this->params = new Data(array_keys($args)); $this->params->load($args); }
/** * @test */ public function route() { $routeEventValues = ['request' => $this->mockedRequest]; $matchEventValues = ['route' => $this->subject->getRoute('test')]; $this->mockedEventDispatcher->shouldReceive('dispatchEvent')->with('router.pre_route', $routeEventValues, $this->subject)->andReturn($this->mockedEvent); $this->mockedEventDispatcher->shouldReceive('dispatchEvent')->with('router.post_route', $routeEventValues, $this->subject)->andReturn($this->mockedEvent); $this->mockedEventDispatcher->shouldReceive('dispatchEvent')->with('router.pre_match', $matchEventValues, $this->subject)->andReturn($this->mockedEvent); $this->mockedEventDispatcher->shouldReceive('dispatchEvent')->with('router.post_match', $matchEventValues, $this->subject)->andReturn($this->mockedEvent); $this->mockedRequest->shouldReceive('getProperties')->andReturn($this->mockedData)->shouldReceive('getPathInfo')->andReturn('/name/first/last'); $this->mockedData->shouldReceive('get')->andReturn($this->mockedData)->shouldReceive('setValues'); $this->assertInstanceOf('Neat\\Http\\Request', $this->subject->route()); }
/** * Parses comment. * * @param string $comment * * @return void */ private function parseComment($comment) { $lines = explode(PHP_EOL, $comment); foreach ($lines as $line) { $pos = stripos($line, '@property-read'); if ($pos !== false) { $isReadonly = true; } else { $pos = stripos($line, '@property'); $isReadonly = false; } if (false !== $pos) { $property = explode(' ', preg_replace('/[ ]+/', ' ', substr($line, $pos))); $name = $property[1]; if (3 == count($property)) { $name = $property[2]; $type = $property[1]; } if ('$' == $name[0]) { $name = substr($name, 1); } $this->properties->init($name, null, $isReadonly); if (isset($type)) { $this->properties->getValidator()->append($name, $type); } } } }
/** * Matches a URI. * * @param string $uri * * @return bool */ public function match($uri) { $regexPattern = $this->parse(); if (!preg_match($regexPattern, $uri, $matches)) { $this->error = sprintf('Pattern "%s" does not match uri "%s".', $this->pattern, $uri); return false; } $values = []; foreach ($matches as $key => $value) { if (is_int($key)) { continue; } $value = urldecode($value); if (isset($this->wildcards[$key])) { $value = explode('/', $value); } $values[$key] = $value; } try { $this->urlParams->setValues($values); $this->error = null; } catch (DataException $e) { $this->error = $e->getMessage(); return false; } return true; }
public function testToArray_returnsArray() { $this->subject->load(['offset1' => '']); $this->subject['offset3']['offset1'] = 1; $this->subject['offset3']['offset2'] = ''; $this->subject['offset3']['offset3'] = 'test'; $expected = ['offset1' => 'filtrated', 'offset2' => null, 'offset3' => ['offset1' => 1, 'offset2' => '', 'offset3' => 'test'], 'offset4' => ['offset1' => null, 'offset2' => null, 'offset3' => null]]; $this->assertSame($expected, $this->subject->toArray()); }
/** * Searches data for not empty value. * * @param Data $data * * @return string */ private function search(Data $data) { $args = func_get_args(); array_shift($args); foreach ($args as $name) { if ($data->has($name)) { $value = $data->get($name); if (!empty($value)) { return $value; } } } return ''; }