Пример #1
0
 public function testGetUriPatternSegments()
 {
     $route = new Route('GET', 'blog/::year/:month/:title', 'MyController@myMethod', array('year' => '/^\\d+$/', 'month' => '/^\\d+$/', 'title' => '/^\\w+$/'));
     $this->assertEquals(array('blog', '::year', ':month', ':title'), $route->getUriPatternSegments());
 }
Пример #2
0
 public function getSlugValues(Route $route, $onlyArgs = false)
 {
     /*
      * Callback to remove any static segment from a segments' array.
      */
     if (!$onlyArgs) {
         $filter = function ($el) {
             return substr($el, 0, 1) === ':';
         };
     } else {
         $filter = function ($el) {
             return substr($el, 0, 1) === ':' && substr($el, 0, 2) !== '::';
         };
     }
     /*
      * Get variable (non static) URI pattern segments without the ":".
      */
     $uriPatternSegments = array_map(function ($el) {
         return str_replace(':', '', $el);
     }, array_filter($route->getUriPatternSegments(), $filter));
     $uriSegments = $this->getRequestUriSegments();
     $values = array();
     foreach ($uriPatternSegments as $k => $s) {
         $values[$s] = $uriSegments[$k];
     }
     return $values;
 }