作者:jrode
项目:Yoso
public function onBootstrap(MvcEvent $e)
{
$callback = function (MvcEvent $event) {
$view = $event->getApplication()->getServiceManager()->get('ViewRenderer');
$config = $event->getApplication()->getConfig();
$controller = $event->getTarget();
$rm = $event->getRouteMatch();
if (!$rm instanceof RouteMatch) {
$rm = new RouteMatch(array('module' => 'Application', '__NAMESPACE__' => 'Application\\Controller', '__CONTROLLER__' => 'index', 'controller' => 'Application\\Controller\\Index', 'action' => 'index'));
}
$params = $rm->getParams();
$modulo = "";
if (isset($params['__NAMESPACE__'])) {
$paramsArray = explode("\\", $params['__NAMESPACE__']);
$modulo = $paramsArray[0];
}
$controller = isset($params['__CONTROLLER__']) ? $params['__CONTROLLER__'] : "";
$action = isset($params['action']) ? $params['action'] : null;
$app = $event->getParam('application');
$sm = $app->getServiceManager();
$paramsConfig = ['modulo' => strtolower($modulo), 'controller' => strtolower($controller), 'action' => strtolower($action), 'baseHost' => $view->base_path("/"), 'cssStaticHost' => "", 'jsStaticHost' => "", 'statHost' => "", 'eHost' => "", 'statVers' => '?', 'min' => '', 'AppCore' => [], 'AppSandbox' => [], 'AppSchema' => ['modules' => [], 'requires' => []]];
$view->inlineScript()->appendScript("var yOSON=" . json_encode($paramsConfig, JSON_FORCE_OBJECT));
};
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', MvcEvent::EVENT_DISPATCH, $callback, 100);
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Application', MvcEvent::EVENT_DISPATCH_ERROR, $callback, 100);
}
作者:benivald
项目:zf2-na-pratic
public function setUp()
{
StaticEventManager::resetInstance();
$mockSharedEventManager = $this->getMock('Zend\EventManager\SharedEventManagerInterface');
$mockSharedEventManager->expects($this->any())->method('getListeners')->will($this->returnValue(array()));
$mockEventManager = $this->getMock('Zend\EventManager\EventManagerInterface');
$mockEventManager->expects($this->any())->method('getSharedManager')->will($this->returnValue($mockSharedEventManager));
$mockApplication = $this->getMock('Zend\Mvc\ApplicationInterface');
$mockApplication->expects($this->any())->method('getEventManager')->will($this->returnValue($mockEventManager));
$event = new MvcEvent();
$event->setApplication($mockApplication);
$event->setRequest(new Request());
$event->setResponse(new Response());
$routeMatch = new RouteMatch(array('action' => 'test'));
$routeMatch->setMatchedRouteName('some-route');
$event->setRouteMatch($routeMatch);
$locator = new Locator;
$locator->add('forward', function () {
return new ForwardController();
});
$this->controller = new SampleController();
$this->controller->setEvent($event);
$this->controller->setServiceLocator($locator);
$this->plugin = $this->controller->plugin('forward');
}
作者:andreas-serl
项目:athene
public function onDispatch(Event $event)
{
$controller = $event->getTarget();
if (!$controller instanceof AbstractController) {
return;
}
$entity = $controller->getEntity();
if (!$entity) {
return;
}
$terms = $entity->getTaxonomyTerms();
if ($terms->isEmpty()) {
foreach ($entity->getParents('link') as $parent) {
$terms = $parent->getTaxonomyTerms();
if (!$terms->isEmpty()) {
break;
}
}
}
$term = $this->strategy->findBranch($terms);
if ($term) {
/* @var $navigationFactory DefaultNavigationFactory */
$navigationFactory = $controller->getServiceLocator()->get('Navigation\\Factory\\DefaultNavigationFactory');
$params = ['term' => $term->getId(), 'controller' => 'Taxonomy\\Controller\\GetController', 'action' => 'index'];
$routeMatch = new RouteMatch($params);
$routeMatch->setMatchedRouteName('taxonomy/term/get');
$navigationFactory->setRouteMatch($routeMatch);
}
}
作者:gstearmi
项目:EshopVegeTabl
/**
* Retrieve the version from the route match.
*
* The route prototype sets "version", while the Content-Type listener sets
* "zf_ver_version"; check both to obtain the version, giving priority to the
* route prototype result.
*
* @param RouteMatch $routeMatches
* @return int|false
*/
protected function getVersionFromRouteMatch(RouteMatch $routeMatches)
{
$version = $routeMatches->getParam('zf_ver_version', false);
if ($version) {
return $version;
}
return $routeMatches->getParam('version', false);
}
作者:haoyanfe
项目:zf
public function testIsActiveReturnsFalseWhenMatchingRouteButNonMatchingParams()
{
$page = new Page\Mvc(array('label' => 'foo', 'route' => 'bar', 'action' => 'baz'));
$routeMatch = new RouteMatch(array());
$routeMatch->setMatchedRouteName('bar');
$routeMatch->setParam('action', 'qux');
$page->setRouteMatch($routeMatch);
$this->assertFalse($page->isActive());
}
作者:aerisweathe
项目:ZfAut
protected function getAllowedRoles(RouteMatch $routeMatch)
{
$controller = strtolower($routeMatch->getParam('controller'));
$action = strtolower($routeMatch->getParam('action'));
$restAction = strtolower($routeMatch->getParam('restAction'));
$rolesByAction = @$this->rules[$controller] ?: [];
$roles = @$rolesByAction[$action] ?: @$rolesByAction[$restAction];
$roles = $roles ?: @$rolesByAction['*'];
return $roles;
}
作者:stavareng
项目:sta-common
public static function fromRoute(\Zend\Mvc\Router\RouteMatch $route)
{
$internalRoute = new self();
$internalRoute->setRoute($route->getMatchedRouteName());
$internalRoute->setParams($route->getParams());
if ($_GET) {
$internalRoute->setOptions(array('query' => $_GET));
}
return $internalRoute;
}
作者:xemloc
项目:Zf1Modul
public function onDispatchError(MvcEvent $e)
{
if ($e->getError() !== Zf2Application::ERROR_ROUTER_NO_MATCH) {
return;
}
$routeMatch = new RouteMatch(array());
$routeMatch->setParam('controller', 'Zf1Module\\DispatchController');
$e->setError(null);
$e->setRouteMatch($routeMatch);
return $routeMatch;
}
作者:zoopcommerc
项目:shard-modul
public static function resolveController(RouteMatch $routeMatch)
{
if ($routeMatch->getMatchedRouteName() != 'rest') {
return;
}
if ($endpoint = $routeMatch->getParam('endpoint')) {
$routeMatch->setParam('controller', 'shard.rest.' . $endpoint);
} else {
$routeMatch->setParam('controller', 'shard.rest');
}
}
作者:robertodormepoc
项目: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());
}
作者:cross-solutio
项目:yawi
public function testSetsActiveFlagOnPagesProvidingTheActiveOnOption()
{
$pages = ['page1' => ['active_on' => 'matchedRouteName'], 'page2' => ['active_on' => 'notMatchedRoute'], 'page3' => ['active_on' => ['matchedRouteName', 'anotherRoute']], 'page4' => []];
$routeMatch = new RouteMatch([]);
$routeMatch->setMatchedRouteName('matchedRouteName');
$expect = $pages;
$expect['page1']['active'] = true;
$expect['page3']['active'] = true;
$m = new \ReflectionMethod($this->target, 'injectComponents');
$m->setAccessible(true);
$actual = $m->invoke($this->target, $pages, $routeMatch);
$this->assertEquals($expect, $actual);
}
作者:stefanor
项目:zf2-fullpage-cach
/**
* @param array $routes
* @param string $route
* @param boolean $expectedResult
* @param array $params
* @param string $httpMethod
* @dataProvider shouldCacheProvider
*/
public function testShouldCache($routes, $route, $expectedResult, $params = array(), $httpMethod = null)
{
$this->strategy->setRoutes($routes);
$routeMatch = new RouteMatch($params);
$routeMatch->setMatchedRouteName($route);
$request = new Request();
if ($httpMethod !== null) {
$request->setMethod($httpMethod);
}
$mvcEvent = new MvcEvent();
$mvcEvent->setRouteMatch($routeMatch);
$mvcEvent->setRequest($request);
$this->assertEquals($expectedResult, $this->strategy->shouldCache($mvcEvent));
}
作者:noopabl
项目:zf
public function setUp()
{
StaticEventManager::resetInstance();
$mockSharedEventManager = $this->getMock('Zend\\EventManager\\SharedEventManagerInterface');
$mockSharedEventManager->expects($this->any())->method('getListeners')->will($this->returnValue(array()));
$mockEventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface');
$mockEventManager->expects($this->any())->method('getSharedManager')->will($this->returnValue($mockSharedEventManager));
$mockApplication = $this->getMock('Zend\\Mvc\\ApplicationInterface');
$mockApplication->expects($this->any())->method('getEventManager')->will($this->returnValue($mockEventManager));
$event = new MvcEvent();
$event->setApplication($mockApplication);
$event->setRequest(new Request());
$event->setResponse(new Response());
$routeMatch = new RouteMatch(array('action' => 'test'));
$routeMatch->setMatchedRouteName('some-route');
$event->setRouteMatch($routeMatch);
$services = new Locator();
$plugins = $this->plugins = new PluginManager();
$plugins->setServiceLocator($services);
$controllers = $this->controllers = new ControllerManager();
$controllers->setFactory('forward', function () use($plugins) {
$controller = new ForwardController();
$controller->setPluginManager($plugins);
return $controller;
});
$controllers->setInvokableClass('ZendTest\\Mvc\\Controller\\TestAsset\\ForwardFq', 'ZendTest\\Mvc\\Controller\\TestAsset\\ForwardFqController');
$controllers->setServiceLocator($services);
$controllerLoader = function () use($controllers) {
return $controllers;
};
$services->add('ControllerLoader', $controllerLoader);
$services->add('ControllerManager', $controllerLoader);
$services->add('ControllerPluginManager', function () use($plugins) {
return $plugins;
});
$services->add('Zend\\ServiceManager\\ServiceLocatorInterface', function () use($services) {
return $services;
});
$services->add('EventManager', function () use($mockEventManager) {
return $mockEventManager;
});
$services->add('SharedEventManager', function () use($mockSharedEventManager) {
return $mockSharedEventManager;
});
$this->controller = new SampleController();
$this->controller->setEvent($event);
$this->controller->setServiceLocator($services);
$this->controller->setPluginManager($plugins);
$this->plugin = $this->controller->plugin('forward');
}
作者:andreas-serl
项目:athene
/**
* {@inheritDoc}
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
/* @var $serviceLocator AbstractPluginManager */
$serviceManager = $serviceLocator->getServiceLocator();
$response = $serviceManager->get('Response');
$request = $serviceManager->get('Request');
$router = $serviceManager->get('Router');
$routeMatch = $router->match($request);
$class = $this->getClass();
if (null === $routeMatch) {
$routeMatch = new RouteMatch([]);
$routeMatch->setMatchedRouteName('home');
}
return new $class($response, $router, $routeMatch);
}
作者:zpet
项目:apigility-routeaccep
/**
* Inject regex matches into the route matches
*
* @param RouteMatch $routeMatches
*/
protected function injectRouteMatches(RouteMatch $routeMatches, $matches)
{
if (!class_exists('\\ZF\\Apigility\\Admin\\Module', false)) {
$vendor = $matches['zf_ver_vendor'];
$version = $matches['zf_ver_version'];
$controllerTest = $vendor . '\\V' . $version;
if (strpos($routeMatches->getParam('controller'), $controllerTest) !== 0) {
$controllerParts = explode('\\', $routeMatches->getParam('controller'));
$controllerParts[0] = $vendor;
$controllerParts[1] = 'V' . $version;
$controller = implode('\\', $controllerParts);
$routeMatches->setParam('controller', $controller);
}
}
}
作者:Theodi
项目:theodia.or
/**
* Create the modelResource that will be used in ACL checks
* @param \Zend\Mvc\Router\RouteMatch $routeMatch
* @param Request $request
* @param type $resourceString
* @return \Application\Authorization\ModelResource
*/
private function getModelResource(\Zend\Mvc\Router\RouteMatch $routeMatch, Request $request, $resourceString)
{
$controller = $routeMatch->getParam('controller', false);
$identifierName = $this->restControllers[$controller];
$id = $this->getIdentifier($identifierName, $routeMatch, $request);
$model = $this->config['zf-rest'][$controller]['entity_class'];
// If we are trying to create a new relation object, then we need to get ACL
// from the pre-existing objects in DB, so we adapt a few things
if (array_key_exists($resourceString, $this->mapping)) {
$mapping = $this->mapping[$resourceString];
$model = $mapping['model'];
$id = $this->getId($request, $mapping['id']);
}
return new ModelResource($resourceString, $model, $id);
}
作者:usba
项目:entilocal
protected function setUp()
{
$serviceManagerGrabber = new ServiceManagerGrabber();
$this->serviceManager = $serviceManagerGrabber->getServiceManager();
$this->serviceManager->setAllowOverride(true);
$this->serviceManager->setService('doctrine.entitymanager.orm_default', $this->getEntityManagerMock());
$config = $this->serviceManager->get('Config');
$this->request = new PhpEnviromentRequest();
$this->router = HttpRouter::factory(isset($config['router']) ? $config['router'] : array());
$this->routeMatch = new RouteMatch(array('controller' => 'index'));
$this->routeMatch->setParam('lang', 'it');
$this->event = new MvcEvent();
$this->event->setRouter($this->router);
$this->event->setRouteMatch($this->routeMatch);
}
作者:grizzm
项目:zf2-for-
/**
* Mimics zf1 Request::getParam behavior
*
* Route match -> GET -> POST
*/
public static function staticGetParam(RouteMatch $routeMatch, Request $request, $param = null, $default = null)
{
if ($param === null) {
$params = (array) $routeMatch->getParams();
if ($request instanceof ConsoleRequest) {
return $params + (array) $request->getParams();
}
return $params + $request->getQuery()->toArray() + $request->getPost()->toArray();
}
if ($request instanceof ConsoleRequest) {
$default = $request->getParam($param, $default);
} else {
$default = $request->getQuery($param, $request->getPost($param, $default));
}
return $routeMatch->getParam($param, $default);
}
作者:ranxin102
项目:zf
/**
* Returns whether page should be considered active or not
*
* This method will compare the page properties against the route matches
* composed in the object.
*
* @param bool $recursive [optional] whether page should be considered
* active if any child pages are active. Default is
* false.
* @return bool whether page should be considered active or not
*/
public function isActive($recursive = false)
{
if (!$this->active) {
$reqParams = array();
if ($this->routeMatch instanceof RouteMatch) {
$reqParams = $this->routeMatch->getParams();
if ($this->routeMatch->getMatchedRouteName() === $this->getRoute()) {
$this->active = true;
return true;
}
}
$myParams = $this->params;
if (null !== $this->controller) {
$myParams['controller'] = $this->controller;
} else {
/**
* @todo In ZF1, this was configurable and pulled from the front controller
*/
$myParams['controller'] = 'index';
}
if (null !== $this->action) {
$myParams['action'] = $this->action;
} else {
/**
* @todo In ZF1, this was configurable and pulled from the front controller
*/
$myParams['action'] = 'action';
}
if (count(array_intersect_assoc($reqParams, $myParams)) == count($myParams)) {
$this->active = true;
return true;
}
}
return parent::isActive($recursive);
}
作者:stefanor
项目:zf2-fullpage-cach
/**
* Check if we should cache the request based on the params in the routematch
*
* @param RouteMatch $match
* @param array $routeConfig
* @return bool
*/
protected function checkParams(RouteMatch $match, $routeConfig)
{
if (!isset($routeConfig['params'])) {
return true;
}
$params = (array) $routeConfig['params'];
foreach ($params as $name => $value) {
$param = $match->getParam($name, null);
if (null === $param) {
continue;
}
if (!$this->checkParam($param, $value)) {
return false;
}
}
return true;
}