作者:rhys
项目:zf2asseti
protected function createRouter()
{
$route = new RegexRoute('/assets/(?<resourcePath>.*)', '/assets/%resourcePath%');
$router = new TreeRouteStack();
$router->addRoute('asset', $route);
return $router;
}
作者:antaru
项目:mystra-pv
public function setUp()
{
$this->router = $router = new TreeRouteStack();
$route = new Segment('/resource[/[:id]]');
$router->addRoute('resource', $route);
$route2 = new Segment('/help');
$router->addRoute('docs', $route2);
$router->addRoute('hostname', ['type' => 'hostname', 'options' => ['route' => 'localhost.localdomain'], 'child_routes' => ['resource' => ['type' => 'segment', 'options' => ['route' => '/resource[/:id]'], 'may_terminate' => true, 'child_routes' => ['children' => ['type' => 'literal', 'options' => ['route' => '/children']]]], 'users' => ['type' => 'segment', 'options' => ['route' => '/users[/:id]']], 'contacts' => ['type' => 'segment', 'options' => ['route' => '/contacts[/:id]']], 'embedded' => ['type' => 'segment', 'options' => ['route' => '/embedded[/:id]']], 'embedded_custom' => ['type' => 'segment', 'options' => ['route' => '/embedded_custom[/:custom_id]']]]]);
$this->event = $event = new MvcEvent();
$event->setRouter($router);
$router->setRequestUri(new Http('http://localhost.localdomain/resource'));
$controller = $this->controller = $this->getMock('Zend\\Mvc\\Controller\\AbstractRestfulController');
$controller->expects($this->any())->method('getEvent')->will($this->returnValue($event));
$this->urlHelper = $urlHelper = new UrlHelper();
$urlHelper->setRouter($router);
$this->serverUrlHelper = $serverUrlHelper = new ServerUrlHelper();
$serverUrlHelper->setScheme('http');
$serverUrlHelper->setHost('localhost.localdomain');
$this->plugin = $plugin = new HalHelper();
$plugin->setController($controller);
$plugin->setUrlHelper($urlHelper);
$plugin->setServerUrlHelper($serverUrlHelper);
$linkExtractor = new LinkExtractor($serverUrlHelper, $urlHelper);
$linkCollectionExtractor = new LinkCollectionExtractor($linkExtractor);
$plugin->setLinkCollectionExtractor($linkCollectionExtractor);
}
作者:totoloui
项目:ZF2-Aut
/**
* Create and return the router
*
* Retrieves the "router" key of the Config service, and uses it
* to instantiate the router. Uses the TreeRouteStack implementation by
* default.
*
* @param ServiceLocatorInterface $serviceLocator
* @param string|null $cName
* @param string|null $rName
* @return \Zend\Mvc\Router\RouteStackInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator, $cName = null, $rName = null)
{
$config = $serviceLocator->get('Config');
$routePluginManager = $serviceLocator->get('RoutePluginManager');
if ($rName === 'ConsoleRouter' || $cName === 'router' && Console::isConsole()) {
// We are in a console, use console router.
if (isset($config['console']) && isset($config['console']['router'])) {
$routerConfig = $config['console']['router'];
} else {
$routerConfig = array();
}
$router = new ConsoleRouter($routePluginManager);
} else {
// This is an HTTP request, so use HTTP router
$router = new HttpRouter($routePluginManager);
$routerConfig = isset($config['router']) ? $config['router'] : array();
}
if (isset($routerConfig['route_plugins'])) {
$router->setRoutePluginManager($routerConfig['route_plugins']);
}
if (isset($routerConfig['routes'])) {
$router->addRoutes($routerConfig['routes']);
}
if (isset($routerConfig['default_params'])) {
$router->setDefaultParams($routerConfig['default_params']);
}
return $router;
}
作者:haoyanfe
项目:zf
public function testIsActiveReturnsTrueWhenMatchingRoute()
{
$page = new Page\Mvc(array('label' => 'spiffyjrwashere', 'route' => 'lolfish'));
$route = new LiteralRoute('/lolfish');
$router = new TreeRouteStack();
$router->addRoute('lolfish', $route);
$routeMatch = new RouteMatch(array());
$routeMatch->setMatchedRouteName('lolfish');
$page->setRouter($router);
$page->setRouteMatch($routeMatch);
$this->assertEquals(true, $page->isActive());
}
作者:nevvermin
项目:zf
public function testHrefGeneratedIsRouteAware()
{
$page = new Page\Mvc(array('label' => 'foo', 'action' => 'myaction', 'controller' => 'mycontroller', 'route' => 'myroute', 'params' => array('page' => 1337)));
$route = new RegexRoute('(lolcat/(?<action>[^/]+)/(?<page>\\d+))', '/lolcat/%action%/%page%', array('controller' => 'foobar', 'action' => 'bazbat', 'page' => 1));
$router = new TreeRouteStack();
$router->addRoute('myroute', $route);
$routeMatch = new RouteMatch(array('controller' => 'foobar', 'action' => 'bazbat', 'page' => 1));
$urlHelper = new UrlHelper();
$urlHelper->setRouter($router);
$urlHelper->setRouteMatch($routeMatch);
$page->setUrlHelper($urlHelper);
$page->setRouteMatch($routeMatch);
$this->assertEquals('/lolcat/myaction/1337', $page->getHref());
}
作者:gstearmi
项目:EshopVegeTabl
private function matchUrl($url, $urlHelper)
{
$url = 'http://localhost.localdomain' . $url;
$request = new Request();
$request->setUri($url);
$router = new TreeRouteStack();
$router->addRoute('hostname', ['type' => 'hostname', 'options' => ['route' => 'localhost.localdomain'], 'child_routes' => ['resource' => ['type' => 'segment', 'options' => ['route' => '/resource[/:id]']]]]);
$match = $router->match($request);
if ($match instanceof RouteMatch) {
$urlHelper->setRouter($router);
$urlHelper->setRouteMatch($match);
}
return $match;
}
作者:gstearmi
项目:EshopVegeTabl
public function setUpRouter()
{
if (isset($this->router)) {
return;
}
$this->setUpRequest();
$routes = ['resource' => ['type' => 'Segment', 'options' => ['route' => '/api/resource[/:id]', 'defaults' => ['controller' => 'Api\\RestController']]]];
$this->router = $router = new TreeRouteStack();
$router->addRoutes($routes);
$matches = $router->match($this->request);
if (!$matches instanceof RouteMatch) {
$this->fail('Failed to route!');
}
$this->matches = $matches;
}
作者:jkhale
项目:LearnZF
public function setUp()
{
$this->request = new Request();
$this->helper = new QueryUrl($this->request);
$this->router = TreeRouteStack::factory(['routes' => ['route-name' => new Literal('/foo/bar')]]);
$this->helper->setRouter($this->router);
}
作者:nield
项目:zf
public function testIsActiveReturnsTrueWhenMatchingRouteWhileUsingModuleRouteListener()
{
$page = new Page\Mvc(array('label' => 'mpinkstonwashere', 'route' => 'roflcopter', 'controller' => 'index'));
$route = new LiteralRoute('/roflcopter');
$router = new TreeRouteStack();
$router->addRoute('roflcopter', $route);
$routeMatch = new RouteMatch(array(ModuleRouteListener::MODULE_NAMESPACE => 'Application\\Controller', 'controller' => 'index'));
$routeMatch->setMatchedRouteName('roflcopter');
$event = new MvcEvent();
$event->setRouter($router)->setRouteMatch($routeMatch);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->onRoute($event);
$page->setRouter($event->getRouter());
$page->setRouteMatch($event->getRouteMatch());
$this->assertEquals(true, $page->isActive());
}
作者:acelay
项目:zf2-acqrcod
public function setUp()
{
$config = (include __DIR__ . '/../../../config/module.config.php');
$renderer = new PhpRenderer();
$renderer->setResolver(new TemplateMapResolver($config['view_manager']['template_map']));
$router = TreeRouteStack::factory($config['router']);
$this->helper = new QrCodeHelper($renderer, $router, new QrCodeServiceMock('foobar'));
}
作者:pnaq5
项目:zf2dem
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);
}
作者:argentinalui
项目:js_zf2_librar
public function getController($controllerClass, $controllerName, $action, $params = [])
{
$config = $this->getConfig();
$controller = $this->getServiceManager()->get('ControllerLoader')->get($controllerClass);
$event = new MvcEvent();
$routerConfig = isset($config['router']) ? $config['router'] : [];
$router = TreeRouteStack::factory($routerConfig);
$event->setRouter($router);
$event->setRouteMatch(new RouteMatch(['controller' => $controllerName, 'action' => $action] + $params));
$controller->setEvent($event);
return $controller;
}
作者:shitikovkiril
项目:LearnZF
/**
* @return ServiceLocatorInterface
*/
private function createServiceLocator(MvcEvent $e = null)
{
$sm = new ServiceManager();
$sm->setService('Request', new Request());
$sm->setService('Response', new Response());
$sm->setService('EventManager', new EventManager());
$sm->setService('Router', TreeRouteStack::factory(['routes' => []]));
$e = $e ?: new MvcEvent();
$app = $this->prophesize('Zend\\Mvc\\Application');
$app->getMvcEvent()->willReturn($e);
$sm->setService('Application', $app->reveal());
$helperManager = new HelperPluginManager();
$helperManager->setServiceLocator($sm);
return $helperManager;
}
作者:jkhale
项目:LearnZF
/**
* @return ServiceLocatorInterface
*/
private function createServiceLocator(MvcEvent $e = null)
{
$sm = new ServiceManager();
$sm->setService('Request', new Request());
$sm->setService('Response', new Response());
$sm->setService('EventManager', new EventManager());
$sm->setService('Router', TreeRouteStack::factory(['routes' => []]));
$e = $e ?: new MvcEvent();
$app = $this->getMock('Zend\\Mvc\\Application', [], [[], $sm]);
$app->expects($this->any())->method('getMvcEvent')->willReturn($e);
$sm->setService('Application', $app);
$helperManager = new HelperPluginManager();
$helperManager->setServiceLocator($sm);
return $helperManager;
}
作者:ezimue
项目:zend-expressiv
/**
* Attempt to match an incoming request to a registered route.
*
* @param PsrRequest $request
* @return RouteResult
*/
public function match(PsrRequest $request)
{
$match = $this->zf2Router->match(Psr7ServerRequest::toZend($request, true));
if (null === $match) {
return RouteResult::fromRouteFailure();
}
$allowedMethods = $this->getAllowedMethods($match->getMatchedRouteName());
if (!$this->methodIsAllowed($request->getMethod(), $allowedMethods)) {
return RouteResult::fromRouteFailure($allowedMethods);
}
return $this->marshalSuccessResultFromRouteMatch($match);
}
作者:BanterMediaS
项目:majestic3-open-sourc
protected function setUp()
{
//check if child class implements the correct interface
if (!$this instanceof TestCaseAdapterInterface) {
throw new \Exception(__CLASS__ . " : Line " . __LINE__ . " : Test Case could not executed. It must implement FrontCore\\TestsConfig\\TestCaseAdapterInterface", 500);
}
//end if
//check if bootstrap instance has been set
if (!$this->bootstrap) {
throw new \Exception(__CLASS__ . " : Line " . __LINE__ . " : Test Case could not executed. Bootstrap instance is not set", 500);
}
//end if
$this->serviceManager = $this->bootstrap->getServiceManager();
//$this->controller = new IndexController();
$this->request = new Request();
$this->routeMatch = new RouteMatch(array('controller' => 'index'));
$this->event = new MvcEvent();
$config = $this->serviceManager->get('Config');
$routerConfig = isset($config['router']) ? $config['router'] : array();
$router = HttpRouter::factory($routerConfig);
$this->event->setRouter($router);
$this->event->setRouteMatch($this->routeMatch);
//$this->controller->setEvent($this->event);
//$this->controller->setServiceLocator($serviceManager);
//create logged in user
$arr_user_data = array("id" => "1", "uname" => "user", "pword" => "5f4dcc3b5aa765d61d8327deb882cf99", "api_key" => "2c0f-828c-b184-f33f-2944-ad2d-f51c-e17a-7a13-ef2a-f581-8e2b", "phpunit" => TRUE);
$objUserSession = $this->serviceManager->get("FrontUserLogin\\Models\\FrontUserSession")->createUserSession((object) $arr_user_data);
}
作者:noiki
项目:tool
protected function setUpController(\Zend\Mvc\Controller\AbstractActionController $controller)
{
$config = (include 'config/application.config.php');
$serviceManager = new ServiceManager(new ServiceManagerConfig());
$serviceManager->setService('ApplicationConfig', $config);
$serviceManager->get('ModuleManager')->loadModules();
$serviceManager->setAllowOverride(true);
$this->controller = $controller;
$this->request = new Request();
$this->response = new Response();
$this->routeMatch = new RouteMatch(array('controller' => 'index'));
$this->event = new MvcEvent();
$this->event->setRequest($this->request)->setResponse($this->response);
$config = $serviceManager->get('Config');
$routerConfig = isset($config['router']) ? $config['router'] : array();
$router = HttpRouter::factory($routerConfig);
$this->event->setRouter($router);
$this->event->setRouteMatch($this->routeMatch);
$this->controller->setEvent($this->event);
$this->controller->setServiceLocator($serviceManager);
$this->setupForwardPlugin();
$this->setupParamsPlugin();
$this->setupFormPlugin();
$this->setupGridControllerPlugin();
$this->setupControllerFilePlugin();
}
作者:nouro
项目:nouro
public function setUp()
{
$basePath = __DIR__ . '/../../../../../';
$this->setApplicationConfig(include $basePath . 'config/application.config.php');
$serviceManager = Bootstrap::getServiceManager();
$this->controller = new \Galaxy\Controller\IndexController();
$this->request = new Request();
$this->routeMatch = new RouteMatch(array('controller' => 'index'));
$this->event = new MvcEvent();
$config = $serviceManager->get('Config');
$routerConfig = isset($config['router']) ? $config['router'] : array();
$router = HttpRouter::factory($routerConfig);
$this->event->setRouter($router);
$this->event->setRouteMatch($this->routeMatch);
$this->controller->setEvent($this->event);
$this->controller->setServiceLocator($serviceManager);
$mockAuth = $this->getMock('ZfcUser\\Entity\\UserInterface');
$ZfcUserMock = $this->getMock('User\\Entity\\User');
$ZfcUserMock->expects($this->any())->method('getId')->will($this->returnValue('3'));
$authMock = $this->getMock('ZfcUser\\Controller\\Plugin\\ZfcUserAuthentication');
$authMock->expects($this->any())->method('hasIdentity')->will($this->returnValue(true));
$authMock->expects($this->any())->method('getIdentity')->will($this->returnValue($ZfcUserMock));
$this->controller->getPluginManager()->setService('zfcUserAuthentication', $authMock);
parent::setUp();
}
作者:weierophinne
项目:zend-expressive-zendroute
/**
* Inject route into the underlying router implemetation.
*
* @param Route $route
*/
private function injectRoute(Route $route)
{
$name = $route->getName();
$path = $route->getPath();
$options = $route->getOptions();
$options = array_replace_recursive($options, ['route' => $path, 'defaults' => ['middleware' => $route->getMiddleware()]]);
$allowedMethods = $route->getAllowedMethods();
if (Route::HTTP_METHOD_ANY === $allowedMethods) {
$this->zendRouter->addRoute($name, ['type' => 'segment', 'options' => $options]);
$this->routeNameMap[$name] = $name;
return;
}
// Remove the middleware from the segment route in favor of method route
unset($options['defaults']['middleware']);
if (empty($options['defaults'])) {
unset($options['defaults']);
}
$httpMethodRouteName = implode(':', $allowedMethods);
$httpMethodRoute = $this->createHttpMethodRoute($route);
$methodNotAllowedRoute = $this->createMethodNotAllowedRoute($path);
$spec = ['type' => 'segment', 'options' => $options, 'may_terminate' => false, 'child_routes' => [$httpMethodRouteName => $httpMethodRoute, self::METHOD_NOT_ALLOWED_ROUTE => $methodNotAllowedRoute]];
if (array_key_exists($path, $this->allowedMethodsByPath)) {
$allowedMethods = array_merge($this->allowedMethodsByPath[$path], $allowedMethods);
// Remove the method not allowed route as it is already present for the path
unset($spec['child_routes'][self::METHOD_NOT_ALLOWED_ROUTE]);
}
$this->zendRouter->addRoute($name, $spec);
$this->allowedMethodsByPath[$path] = $allowedMethods;
$this->routeNameMap[$name] = sprintf('%s/%s', $name, $httpMethodRouteName);
}
作者:flipecristia
项目:apiZen
/**
* {@inheritDoc}
*/
public function generateUri($name, array $substitutions = [])
{
if (!$this->zf2Router->hasRoute($name)) {
throw new Exception\RuntimeException(sprintf('Cannot generate URI based on route "%s"; route not found', $name));
}
$name = isset($this->routeNameMap[$name]) ? $this->routeNameMap[$name] : $name;
$options = ['name' => $name, 'only_return_path' => true];
return $this->zf2Router->assemble($substitutions, $options);
}