/** * @dataProvider routeProvider * @param Literal $route * @param string $path * @param integer $offset * @param boolean $shouldMatch */ public function testAssembling(Literal $route, $path, $offset, $shouldMatch) { if (!$shouldMatch) { // Data which will not match are not tested for assembling. return; } $result = $route->assemble(); if ($offset !== null) { $this->assertEquals($offset, strpos($path, $result, $offset)); } else { $this->assertEquals($path, $result); } }
public function match(RequestInterface $request, $pathOffset = null, array $options = array()) { $routeMatch = parent::match($request, $pathOffset, $options); /* @var callable $test */ $test = $this->defaults['test']; $result = $test($request, $this->getServiceManager()); return $result ? $routeMatch : null; }
public function setUp() { $router = new SimpleRouteStack(); $router->addRoute('home', LiteralRoute::factory(array('route' => '/', 'defaults' => array('controller' => 'ZendTest\\Mvc\\Controller\\TestAsset\\SampleController')))); $event = new MvcEvent(); $event->setRouter($router); $this->controller = new SampleController(); $this->controller->setEvent($event); $this->plugin = $this->controller->plugin('url'); }
public function setupPathController() { $request = $this->serviceManager->get('Request'); $uri = UriFactory::factory('http://example.local/path'); $request->setUri($uri); $router = $this->serviceManager->get('HttpRouter'); $route = Router\Http\Literal::factory(array('route' => '/path', 'defaults' => array('controller' => 'path'))); $router->addRoute('path', $route); $this->application->bootstrap(); }
public function onBootstrap(eventInterface $e) { $application = $e->getTarget(); $event = $application->getEventManager(); $event->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (MvcEvent $e) { error_log($e->getError()); error_log($e->getControllerClass() . ' ' . $e->getController()); error_log('exception' . $e->getParam('exception')->getMessage()); }); $sm = $application->getServiceManager(); $router = $sm->get('Router'); $router->addRoute('principale', Literal::factory(array('route' => '/', 'defaults' => array('controller' => 'index', 'action' => 'index')))); }
public function setUp() { $router = new SimpleRouteStack(); $router->addRoute('home', LiteralRoute::factory(array('route' => '/', 'defaults' => array('controller' => 'ZendTest\\Mvc\\Controller\\TestAsset\\SampleController')))); $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); }
public function setUp() { $this->response = new Response(); $router = new SimpleRouteStack(); $router->addRoute('home', LiteralRoute::factory(array('route' => '/', 'defaults' => array('controller' => 'ZendTest\\Mvc\\Controller\\TestAsset\\SampleController')))); $this->router = $router; $routeMatch = new RouteMatch(array()); $routeMatch->setMatchedRouteName('home'); $this->routeMatch = $routeMatch; $event = new MvcEvent(); $event->setRouter($router); $event->setResponse($this->response); $this->event = $event; $this->controller = new SampleController(); $this->controller->setEvent($event); $this->plugin = $this->controller->plugin('redirect'); }
public function setUp() { $router = new TreeRouteStack(); $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', 'controller' => 'sample')))); $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); $plugins = $this->controller->getPluginManager(); $plugins->get('flashmessenger')->setSessionManager($this->sessionManager); }
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); }
public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); $serviceManager = $e->getApplication()->getServiceManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); StaticFilter::getPluginManager()->setInvokableClass("Callback", "\\ZendVN\\Event\\Callback"); $eventManager->attach(new \ZendVN\Event\ShowInfoListener()); //create Router $literal = \Zend\Mvc\Router\Http\Literal::factory(array('route' => '/new-way.html', 'defaults' => array('__NAMESPACE__' => 'Mvc\\Controller', 'controller' => 'Router', 'action' => 'contact'))); $route = $e->getRouter(); $route->addRoute('newway', $literal); //set private template Error //$eventManager->attach("dispatch",array($this,"loadError")); //$eventManager->attach("render",array($this,"setTitle")); //$serviceManager->setInvokableClass("YourService","Mvc\Service\UserService"); //set Service on Module.php //userService = $serviceManager->get("socialservice"); // $userService2 = $serviceManager->get("MSU"); // echo "<pre style='font-weight:bold'>"; // print_r($userService); // echo "</pre>"; // if($serviceManager->has("Mvc\Service\FaceBook")){ // $facebookService = $serviceManager->get("Mvc\Service\FaceBook"); // echo "<pre style='font-weight:bold'>"; // print_r($facebookService); // echo "</pre>"; // }else{ // echo "Not exists this Service"; // } // $showInfoListener = new \ZendVN\Event\ShowInfoListener(); // $showInfoListener->attach($eventManager); //set sharedEventManager // $shareEventManager = $eventManager->getSharedManager(); // $shareEventManager->attach("ZendVN\Event\Foo","showInfo",function($e){ // echo "<h3 style='color:red;font-weight:bold'>showInfo - do 1</h3>"; // echo "<pre style='font-weight:bold'>"; // print_r($e->getParams()); // echo "</pre>"; // }); }
public function setupBadController($addService = true) { $request = $this->serviceManager->get('Request'); $uri = UriFactory::factory('http://example.local/bad'); $request->setUri($uri); $router = $this->serviceManager->get('HttpRouter'); $route = Router\Http\Literal::factory(array('route' => '/bad', 'defaults' => array('controller' => 'bad', 'action' => 'test'))); $router->addRoute('bad', $route); if ($addService) { $controllerLoader = $this->serviceManager->get('ControllerLoader'); $controllerLoader->setFactory('bad', function () { return new Controller\TestAsset\BadController(); }); } $this->application->bootstrap(); }
public function testDispatchingInjectsLocatorInLocatorAwareControllers() { $app = new Application(); $request = new Request(); $uri = UriFactory::factory('http://example.local/locator-aware'); $request->setUri($uri); $app->setRequest($request); $route = Router\Http\Literal::factory(array('route' => '/locator-aware', 'defaults' => array('controller' => 'locator-aware'))); $router = $app->getRouter(); $router->addRoute('locator-aware', $route); $locator = new TestAsset\Locator(); $locator->add('locator-aware', function () { return new TestAsset\LocatorAwareController(); }); $app->setLocator($locator); $storage = new ArrayObject(); $events = StaticEventManager::getInstance(); $events->attach('ZendTest\\Mvc\\TestAsset\\LocatorAwareController', 'dispatch', function ($e) use($storage) { $controller = $e->getTarget(); $storage['locator'] = $controller->getLocator(); return $e->getResponse(); }, 100); $app->run(); $this->assertTrue(isset($storage['locator'])); $this->assertSame($locator, $storage['locator']); }
public function testGetAssembledParams() { $route = new Literal('/foo'); $route->assemble(array('foo' => 'bar')); $this->assertEquals(array(), $route->getAssembledParams()); }
/** * @group ZF2-436 */ public function testEmptyLiteral() { $request = new Request(); $route = new Literal(''); $this->assertNull($route->match($request, 0)); }
/** * @param MvcEvent $event */ public function handleError(MvcEvent $event) { // Do nothing if no error in the event $error = $event->getError(); if (empty($error)) { return; } switch ($error) { case Application::ERROR_CONTROLLER_NOT_FOUND: case Application::ERROR_CONTROLLER_INVALID: // Specifically not handling these return; break; case Application::ERROR_ROUTER_NO_MATCH: if ($event->getName() == MvcEvent::EVENT_DISPATCH_ERROR) { // add dummy 'no-route' route to silent routeMatch errors $noRoute = 'no-route'; $event->getRouter()->addRoute($noRoute, Router\Http\Literal::factory(['route' => ''])); $event->setRouteMatch((new Router\RouteMatch([]))->setMatchedRouteName($noRoute)); } break; case Application::ERROR_EXCEPTION: default: $exception = $event->getParam('exception'); $logMessages = array(); do { $priority = Logger::ERR; $extra = array('file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTrace()); if (isset($exception->xdebug_message)) { $extra['xdebug'] = $exception->xdebug_message; } $logMessages[] = array('priority' => $priority, 'message' => $exception->getMessage(), 'extra' => $extra); $exception = $exception->getPrevious(); } while ($exception); foreach (array_reverse($logMessages) as $logMessage) { $this->log->log($logMessage['priority'], $logMessage['message'], $logMessage['extra']); } break; } }