Beispiel #1
0
 /**
  * Overridden to handle special options
  *
  * @inheritdoc
  */
 public static function factory($options = array())
 {
     /** @var $instance \Zb\Utils\Hashids\HashidsRouter */
     $instance = parent::factory($options);
     if (isset($options['hashids']) && is_array($options['hashids']) && !empty($options['hashids'])) {
         $instance->setHashidsParams($options['hashids']);
     }
     return $instance;
 }
Beispiel #2
0
 public function setUp()
 {
     $router = new SimpleRouteStack();
     $router->addRoute('home', LiteralRoute::factory(array('route' => '/', 'defaults' => array('controller' => 'ZendTest\\Mvc\\Controller\\TestAsset\\SampleController'))));
     $router->addRoute('sub', SegmentRoute::factory(array('route' => '/foo/:param', 'defaults' => array('param' => 1))));
     $this->controller = new SampleController();
     $this->request = new Request();
     $this->event = new MvcEvent();
     $this->routeMatch = new RouteMatch(array('controller' => 'controller-sample', 'action' => 'postPage'));
     $this->event->setRequest($this->request);
     $this->event->setRouteMatch($this->routeMatch);
     $this->event->setRouter($router);
     $this->sessionManager = new SessionManager();
     $this->sessionManager->destroy();
     $this->controller->setEvent($this->event);
     $this->controller->flashMessenger()->setSessionManager($this->sessionManager);
 }
 private function generateRoute(MvcEvent $e)
 {
     if (!$this->cacheRouteData) {
         $sm = $e->getApplication()->getServiceManager();
         $this->cacheRouteData = $sm->get('RouteData');
     }
     try {
         $router = $e->getRouter();
         foreach ($this->cacheRouteData as $data) {
             $constraints = json_decode($data['constraints'], true);
             $data['constraints'] = $constraints;
             $data['defaults'] = array('controller' => $data['controller'], 'action' => 'index');
             $route = Segment::factory($data);
             $router->addRoute($data['name'], $route);
         }
         $this->hasRoute = true;
     } catch (\Exception $ex) {
         throw $ex;
     }
 }
 public function setUp()
 {
     $this->form = new Form();
     $this->collection = new Collection('links', array('count' => 1, 'allow_add' => true, 'target_element' => array('type' => 'ZendTest\\Mvc\\Controller\\Plugin\\TestAsset\\LinksFieldset')));
     $router = new SimpleRouteStack();
     $router->addRoute('home', LiteralRoute::factory(array('route' => '/', 'defaults' => array('controller' => 'ZendTest\\Mvc\\Controller\\TestAsset\\SampleController'))));
     $router->addRoute('sub', SegmentRoute::factory(array('route' => '/foo/:param', 'defaults' => array('param' => 1))));
     $router->addRoute('ctl', SegmentRoute::factory(array('route' => '/ctl/:controller', 'defaults' => array('__NAMESPACE__' => 'ZendTest\\Mvc\\Controller\\TestAsset'))));
     $this->controller = new SampleController();
     $this->request = new Request();
     $this->event = new MvcEvent();
     $this->routeMatch = new RouteMatch(array('controller' => 'controller-sample', 'action' => 'postPage'));
     $this->event->setRequest($this->request);
     $this->event->setRouteMatch($this->routeMatch);
     $this->event->setRouter($router);
     $this->sessionManager = new SessionManager();
     $this->sessionManager->destroy();
     $this->controller->setEvent($this->event);
     $this->controller->flashMessenger()->setSessionManager($this->sessionManager);
 }
 /**
  * Get an initialized instance of the controller plugin
  *
  * If controller setup is requested, the controller will be a
  * \Library\Test\Mvc\Controller\TestController. Its MvcEvent will be
  * initialized with a standard route 'test' (/module/controller/action/)
  * with defaults of "defaultcontroller" and "defaultaction".
  * The RouteMatch is initialized with "currentcontroller" and
  * "currentaction". An empty response is created.
  *
  * @param bool $setController Initialize the helper with a working controller (default: TRUE)
  * @return \Zend\Mvc\Controller\Plugin\PluginInterface Plugin instance
  */
 protected function _getPlugin($setController = true)
 {
     if ($setController) {
         $router = new \Zend\Mvc\Router\Http\TreeRouteStack();
         $router->addRoute('test', \Zend\Mvc\Router\Http\Segment::factory(array('route' => '/[module[/]][:controller[/][:action[/]]]', 'defaults' => array('controller' => 'defaultcontroller', 'action' => 'defaultaction'))));
         $routeMatch = new \Zend\Mvc\Router\RouteMatch(array('controller' => 'currentcontroller', 'action' => 'currentaction'));
         $routeMatch->setMatchedRouteName('test');
         $event = new \Zend\Mvc\MvcEvent();
         $event->setRouter($router);
         $event->setRouteMatch($routeMatch);
         $event->setResponse(new \Zend\Http\Response());
         // Register TestController with the service manager because this is
         // not done in the module setup
         $manager = Application::getService('ControllerManager');
         $manager->setInvokableClass('test', 'Library\\Test\\Mvc\\Controller\\TestController');
         $this->_controller = $manager->get('test');
         $this->_controller->setEvent($event);
         return $this->_controller->plugin($this->_getPluginName());
     } else {
         return $this->_getPluginManager()->get($this->_getPluginName());
     }
 }
Beispiel #6
0
 public function testCanPassBooleanValueForThirdArgumentToAllowReusingRouteMatches()
 {
     $this->router->addRoute('replace', SegmentRoute::factory(array('route' => '/:controller/:action', 'defaults' => array('controller' => 'ZendTest\\Mvc\\Controller\\TestAsset\\SampleController'))));
     $routeMatch = new RouteMatch(array('controller' => 'foo'));
     $routeMatch->setMatchedRouteName('replace');
     $this->controller->getEvent()->setRouteMatch($routeMatch);
     $url = $this->plugin->fromRoute('replace', array('action' => 'bar'), true);
     $this->assertEquals('/foo/bar', $url);
 }
<?php

require "./vendor/autoload.php";
$route = \Zend\Mvc\Router\Http\Segment::factory(array('route' => '/:controller', 'constraints' => array('controller' => '[A-Za-z]+')));
$req = new \Zend\Http\Request();
$req->setUri($argv[1]);
$match = $route->match($req);
if ($match != null) {
    echo "OK";
} else {
    echo "NOn ok";
}
Beispiel #8
0
<?php

/**
 * Created by PhpStorm.
 * User: user
 * Date: 07/12/15
 * Time: 14:43
 */
require "./vendor/autoload.php";
$route = \Zend\Mvc\Router\Http\Segment::factory(array('route' => '/:chemin', 'constraints' => array('chemin' => '[a-zA-Z]+')));
$req = new \Zend\Http\Request();
$req->setUri('http://monsite/st9');
$match = $route->match($req);
if ($match !== null) {
    echo "ok\n";
} else {
    echo "ressource non connue \n";
}
Beispiel #9
0
<?php

require "./vendor/autoload.php";
$route = \Zend\Mvc\Router\Http\Segment::factory(array('route' => '/:controller', 'constraints' => array('controller' => '[a-zA-Z]+'), 'defaults' => array('param1' => 'val1', 'param2' => 'val2')));
$req = new \Zend\Http\Request();
$req->setUri('http://monsite/stockst');
$match = $route->match($req);
if ($match !== null) {
    echo $match->getParam('param1') . "\n";
} else {
    echo "ressource non connue \n";
}
Beispiel #10
0
 /**
  * Map a route to a callback
  *
  * @param  string|Router\RouteInterface $route
  * @param  callable $controller
  * @return Route
  * @throws Exception\InvalidRouteException
  */
 public function map($route, $controller)
 {
     if (is_string($route)) {
         $route = Router\Http\Segment::factory(array('route' => $route));
     }
     if (!$route instanceof Router\RouteInterface) {
         throw new Exception\InvalidRouteException('Routes are expected to be either strings or instances of Zend\\Mvc\\Router\\RouteInterface');
     }
     $route = new Route($route, $controller);
     $this->routes[] = $route;
     return $route;
 }
Beispiel #11
0
 public function testMapCanReceiveARouteObject()
 {
     $route = Routes\Segment::factory(array('route' => '/:controller'));
     $map = $this->app->map($route, function ($params, $app) {
     });
     $this->assertSame($route, $map->route());
 }
Beispiel #12
0
 private function addRoute($routeName, $route, $routeOptions, $options)
 {
     if (isset($options['routeName'])) {
         $routeName = $options['routeName'];
         unset($options['routeName']);
     }
     if (isset($options['route'])) {
         $route = $options['route'];
         unset($options['route']);
     }
     $routeOptions = array_merge($routeOptions, $options);
     $routeSegment = Segment::factory(['route' => $route, 'defaults' => $routeOptions]);
     $this->router->addRoute($routeName, $routeSegment);
 }
Beispiel #13
0
<?php

require "vendor/autoload.php";
$route = \Zend\Mvc\Router\Http\Segment::factory(array('route' => '/:controller[/:toto]', 'constraints' => array('controller' => '[a-zA-Z][a-zA-Z0-9_-]+', 'toto' => '[a-zA-Z][a-zA-Z0-9_-]+'), 'defaults' => array('controller' => 'Application\\Controller\\IndexController', 'action' => 'index')));
$req = new \Zend\Http\Request();
$req->setUri('http://monsite/stock/inventaire');
$match = $route->match($req);
if ($match !== null) {
    echo $match->getParam('toto') . "\n";
} else {
    echo "ressource non connue \n";
}