コード例 #1
0
ファイル: LiteralTest.php プロジェクト: nsenkevich/zf2
 /**
  * @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);
     }
 }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: UrlTest.php プロジェクト: bradley-holt/zf2
 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');
 }
コード例 #4
0
 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();
 }
コード例 #5
0
ファイル: Module.php プロジェクト: sanPgut/Exos-ZFPhp
 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'))));
 }
コード例 #6
0
ファイル: PostRedirectGetTest.php プロジェクト: haoyanfei/zf2
 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);
 }
コード例 #7
0
ファイル: RedirectTest.php プロジェクト: rajanlamic/IntTest
 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');
 }
コード例 #8
0
 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);
 }
コード例 #9
0
 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);
 }
コード例 #10
0
ファイル: Module.php プロジェクト: trongle/zend-2
 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>";
     // });
 }
コード例 #11
0
 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();
 }
コード例 #12
0
ファイル: ApplicationTest.php プロジェクト: rafalwrzeszcz/zf2
 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']);
 }
コード例 #13
0
ファイル: LiteralTest.php プロジェクト: rikh42/zf2
 public function testGetAssembledParams()
 {
     $route = new Literal('/foo');
     $route->assemble(array('foo' => 'bar'));
     $this->assertEquals(array(), $route->getAssembledParams());
 }
コード例 #14
0
 /**
  * @group ZF2-436
  */
 public function testEmptyLiteral()
 {
     $request = new Request();
     $route = new Literal('');
     $this->assertNull($route->match($request, 0));
 }
コード例 #15
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;
     }
 }