コード例 #1
0
ファイル: Event.php プロジェクト: neatphp/neat
 /**
  * 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);
 }
コード例 #2
0
ファイル: RouterTest.php プロジェクト: neatphp/neat
 /**
  * @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());
 }
コード例 #3
0
ファイル: Object.php プロジェクト: neatphp/neat
 /**
  * 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);
             }
         }
     }
 }
コード例 #4
0
ファイル: Route.php プロジェクト: neatphp/neat
 /**
  * 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;
 }
コード例 #5
0
ファイル: DataTest.php プロジェクト: neatphp/neat
 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());
 }
コード例 #6
0
ファイル: ServerRequest.php プロジェクト: neatphp/neat
 /**
  * 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 '';
 }