Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
 public function getResponse()
 {
     $response = $this->siteAccess->dispatch($this->routeMatch->getParam('path'))->getResponse();
     // Calc total run time
     $this->getServiceLocator()->get('accumulator')->start('Total', SCRIPT_START);
     $this->getServiceLocator()->get('accumulator')->stop('Total');
     $this->getServiceLocator()->get('accumulator')->memory_usage('Before sending response');
     $this->addDebugOutput($response);
     return $response;
 }
Ejemplo n.º 3
0
 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;
 }
 public static function resolveController(RouteMatch $routeMatch)
 {
     if (($extension = $routeMatch->getParam('extension')) && ($manifestName = $routeMatch->getParam('manifestName'))) {
         if ($endpoint = $routeMatch->getParam('endpoint')) {
             $routeMatch->setParam('controller', implode('.', [$extension, $manifestName, $endpoint]));
         } else {
             $routeMatch->setParam('controller', implode('.', [$extension, $manifestName]));
         }
     }
 }
 /**
  * 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);
         }
     }
 }
 /**
  * Prepares the REST Request object with values appropriate for a sub-resource request.
  *
  * @param \BedRest\Rest\Request\Request $restRequest
  * @param \Zend\Http\Request            $httpRequest
  * @param \Zend\Mvc\Router\RouteMatch   $routeMatch
  */
 protected function prepareSubResource(RestRequest $restRequest, HttpRequest $httpRequest, RouteMatch $routeMatch)
 {
     $id = $routeMatch->getParam('id', null);
     $restRequest->setParameter('identifier', $id);
     $resourceName = $routeMatch->getParam('__CONTROLLER__');
     $subResourceName = $routeMatch->getParam('subresource', null);
     $restRequest->setResource($resourceName . '/' . $subResourceName);
     $subId = $routeMatch->getParam('subresource_id', null);
     if (!empty($subId)) {
         $restRequest->setParameter('subresource_identifier', $subId);
     }
     $method = strtoupper($httpRequest->getMethod());
     if (!empty($method)) {
         if (empty($subId) && $method !== RestRequestType::METHOD_POST) {
             $method .= '_COLLECTION';
         }
         $restRequest->setMethod(constant('BedRest\\Rest\\Request\\Type::METHOD_' . $method));
     }
 }
Ejemplo n.º 7
0
 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');
     }
 }
Ejemplo n.º 8
0
 protected function setRouteVariables(RouteMatch $routeMatch)
 {
     $controller = $routeMatch->getParam('controller');
     $controller = strtolower(substr($controller, strrpos($controller, '\\') + 1));
     $action = $routeMatch->getParam('action');
     $route = $routeMatch->getMatchedRouteName();
     $setArray = ['route' => $route, 'controller' => $controller, 'action' => $action];
     $alias = $routeMatch->getParam('alias');
     if ($alias) {
         $setArray['alias'] = $alias;
     }
     $id = $routeMatch->getParam('id');
     if ($id) {
         $setArray['id'] = $id;
     }
     $page = $routeMatch->getParam('page');
     if ($page) {
         $setArray['page'] = $page;
     }
     return $setArray;
 }
 /**
  * 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);
 }
Ejemplo n.º 10
0
 /**
  * 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);
 }
Ejemplo n.º 11
0
 /**
  * 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;
 }
 /**
  * Retrieve the identifier, if any
  *
  * Attempts to see if an identifier was passed in either the URI or the
  * query string, returning if if found. Otherwise, returns a boolean false.
  *
  * @param  \Zend\Mvc\Router\RouteMatch $routeMatch
  * @param  Request $request
  * @return false|mixed
  */
 protected function getIdentifier($routeMatch, $request)
 {
     $id = $routeMatch->getParam('id', false);
     if ($id) {
         return $id;
     }
     $id = $request->getQuery()->get('id', false);
     if ($id) {
         return $id;
     }
     return false;
 }
 /**
  * this is a weird one
  *
  * i noticed a use case during testing where if an unauthenticated user attempts
  * to navigate to a protected route and the destination is saved,
  * they could click on anything else an avoid the authentication process
  * and since the saved destination information is never consumed, it persists
  * and if that user does authenitcate later, it will send them to that
  * initial route whether they had requested it or not
  *
  * this removes that saved information as soon as the user selects a route that does
  * not have the same controller that is used to
  * @param RouteMatch $routeMatch
  */
 private function forgetSavedDestinationWhenNotAuthenticating(RouteMatch $routeMatch)
 {
     /*
      * run dependency check
      */
     $this->checkDependencies();
     $routeForwardingContainer = $this->routeForwardingContainer;
     $controller = $routeMatch->getParam('controller');
     if ($controller != self::UNAUTHENTICATED_CONTROLLER) {
         $routeForwardingContainer->offsetUnset(self::ROUTE_FORWARDING_SESSION_KEY);
     }
 }
 protected function getIdentifier(RouteMatch $routeMatch, RequestInterface $request)
 {
     $identifier = $this->getIdentifierName();
     $id = $routeMatch->getParam($identifier, false);
     if ($id !== false) {
         return $id;
     }
     if ($request instanceof Request) {
         $id = $request->getQuery()->get($identifier, false);
         if ($id !== false) {
             return $id;
         }
     }
     return false;
 }
Ejemplo n.º 15
0
 /**
  * @param RouteMatch $routeMatch
  * @return string
  */
 public static function getKey(RouteMatch $routeMatch)
 {
     return $routeMatch->getParam('controller') . self::KEY_SEPARATOR . $routeMatch->getParam('action');
 }
    /**
     * Retrieve the identifier, if any
     *
     * Attempts to see if an identifier was passed in either the URI or the
     * query string, returning it if found. Otherwise, returns a boolean false.
     *
     * @param  \Zend\Mvc\Router\RouteMatch $routeMatch
     * @param  Request $request
     * @return false|mixed
     */
    protected function getIdentifier($routeMatch, $request)
    {
        $identifier = $this->getIdentifierName();
        $id = $routeMatch->getParam($identifier, false);
        if ($id !== false) {
            return $id;
        }

        $id = $request->getQuery()->get($identifier, false);
        if ($id !== false) {
            return $id;
        }

        return false;
    }
 /**
  * @param RouteMatch $routeMatch
  */
 public function setRouteMatch(RouteMatch $routeMatch)
 {
     $this->routeMatchParamValue = $routeMatch->getParam($this->paramName);
 }
 /**
  * Does the request represent a collection?
  *
  * @param string $serviceName
  * @param array $data
  * @param RouteMatch $matches
  * @param HttpRequest $request
  * @return bool
  */
 protected function isCollection($serviceName, $data, RouteMatch $matches, HttpRequest $request)
 {
     if (!array_key_exists($serviceName, $this->restControllers)) {
         return false;
     }
     if ($request->isPost() && (empty($data) || ArrayUtils::isHashTable($data))) {
         return false;
     }
     $identifierName = $this->restControllers[$serviceName];
     if ($matches->getParam($identifierName)) {
         return false;
     }
     return null === $request->getQuery($identifierName, null);
 }
Ejemplo n.º 19
0
 protected function getIdentifier($identifierName, RouteMatch $routeMatch, $request)
 {
     $id = $routeMatch->getParam($identifierName, false);
     if ($id) {
         return $id;
     }
     if (!$request instanceof Request) {
         return false;
     }
     return $request->getQuery($identifierName, false);
 }
Ejemplo n.º 20
0
 /**
  * Extract the Module name from the namespace
  * @param RouteMatch $routeMatch
  * @return string
  */
 private function getModuleName(RouteMatch $routeMatch)
 {
     return strtolower(strstr($routeMatch->getParam('__NAMESPACE__'), '\\', true));
 }
Ejemplo n.º 21
0
 /**
  * Return currently active sysmap items based on current request or request passed as a parameter
  * @param null|Zend_Controller_Request_Abstract $customRequest
  * @return null|Doctrine_Collection
  */
 public function getActiveItems(\Zend\Mvc\Router\RouteMatch $request)
 {
     $activeItems = array(new \Zend\Acl\Resource\GenericResource($this->getRoot()->hash));
     $sysmap = $this->getSysmap();
     $module = $request->getParam('module', false);
     $controller = $request->getParam('controller', false);
     $action = $request->getParam('action', false);
     if ($module && $controller && $action) {
         foreach ($sysmap as $mname => $mod) {
             if ($mname == $module) {
                 $activeItems[] = new \Zend\Acl\Resource\GenericResource($mod->hash);
                 foreach ($mod->_childrens as $cname => $ctrl) {
                     if ($mname == $module && ($controller = $cname)) {
                         $activeItems[] = new \Zend\Acl\Resource\GenericResource($ctrl->hash);
                         foreach ($ctrl->_childrens as $aname => $act) {
                             if ($mname == $module && ($controller = $cname && $action == $aname)) {
                                 $activeItems[] = new \Zend\Acl\Resource\GenericResource($act->hash);
                             }
                         }
                     }
                 }
             }
         }
     } elseif (!$module && $controller && $action) {
         foreach ($sysmap as $mname => $mod) {
             foreach ($mod->_childrens as $cname => $ctrl) {
                 if ($controller == $cname) {
                     $activeItems[] = new \Zend\Acl\Resource\GenericResource($ctrl->hash);
                     foreach ($ctrl->_childrens as $aname => $act) {
                         if ($controller == $cname && $action == $aname) {
                             $activeItems[] = new \Zend\Acl\Resource\GenericResource($act->hash);
                         }
                     }
                 }
             }
         }
     } else {
         return $activeItems;
     }
     return $activeItems;
 }
Ejemplo n.º 22
0
 public function testGetNonExistentParamWithDefault()
 {
     $match = new RouteMatch(array());
     $this->assertEquals('bar', $match->getParam('foo', 'bar'));
 }
    /**
     * Match the controller to an authentication type, based on the API to
     * which the controller belongs.
     *
     * @param null|RouteMatch $routeMatch
     * @return string|false
     */
    private function getTypeFromMap(RouteMatch $routeMatch = null)
    {
        if (! $routeMatch) {
            return false;
        }

        $controller = $routeMatch->getParam('controller', false);
        if (false === $controller) {
            return false;
        }

        foreach ($this->authMap as $api => $type) {
            $api = rtrim($api, '\\') . '\\';
            if (strlen($api) > strlen($controller)) {
                continue;
            }

            if (0 === strpos($controller, $api)) {
                return $type;
            }
        }

        return false;
    }