Beispiel #1
0
 /**
  * @param string $param
  * @param mixed $default
  * @return mixed
  */
 public function fromQuery($param = null, $default = null)
 {
     if ($param === null) {
         return $this->request->getQuery($param, $default)->toArray();
     }
     return $this->request->getPost($param, $default);
 }
Beispiel #2
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);
 }
 /** {@inheritdoc} */
 public function dispatch(\Zend\Stdlib\RequestInterface $request, \Zend\Stdlib\ResponseInterface $response = null)
 {
     // Fetch group with given name for actions referring to a particular group
     $action = $this->getEvent()->getRouteMatch()->getParam('action');
     if ($action != 'index' and $action != 'add') {
         try {
             $this->_currentGroup = $this->_groupManager->getGroup($request->getQuery('name'));
         } catch (\RuntimeException $e) {
             // Group does not exist - may happen when URL has become stale.
             $this->flashMessenger()->addErrorMessage('The requested group does not exist.');
             return $this->redirectToRoute('group', 'index');
         }
     }
     return parent::dispatch($request, $response);
 }
 /**
  * Verifica permissao de acesso.
  * 
  * @param RequestInterface $request
  * @return type
  */
 public function checkAccess(Request $request)
 {
     // True porque por padrao eh checado o acesso de accessDeniedAction (nao tem acesso)
     $result = true;
     // Validação do parametro MODULO
     $module = $request->getQuery('module', 'application');
     $this->validate('module', $module, array('NotEmpty'));
     $session = new Session(self::ACCESS_CONTROL_NAMESPACE);
     // Parametro Module não encontrado, assim não sabemos
     // que tipo de login ele tem.
     if (!$this->isAllValid()) {
         $this->setError(MsgType::DANGER, "Acesso Negado");
         $session->view = $this->view;
         $result = false;
         // Agora verificamos se o usuario tem permissao de acesso
         // configurado pelo banco de dados
     } else {
         if ($this->getActionName() != 'access-denied') {
             // Puxa configuracoes de acessos do banco de dados
             $accessControl = AccessControl::getInstance($module);
             $accessControl->setupPermissions($this->getLogin() ? $this->getLogin()->getFkRole() : Config::getZf2libConfig('roleDefault'), $module);
             // Setor do sistema
             $permission = array('module' => $this->getModuleName(), 'controller' => $this->getControllerName(), 'action' => $this->getActionName());
             // Quando a acao nao existir na tabela action
             // assumimos que ela eh uma acao de leitura (read)
             $actionBOClass = Config::getZf2libConfig('actionBusinessClass', $module);
             $actionBO = new $actionBOClass();
             $action = $actionBO->get($permission['action']);
             if (!$action) {
                 $permission['action'] = Config::getZf2libConfig('actionRead');
             }
             // Verifica se usuario tem acesso
             $allowed = AccessControl::allowed(implode('.', $permission));
             if (!$allowed) {
                 $this->setError(MsgType::DANGER, "Acesso Negado");
                 $session->view = $this->view;
                 $result = false;
             }
         }
     }
     return $result;
 }
 /**
  * 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;
 }
    /**
     * 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;
    }
 /** {@inheritdoc} */
 public function dispatch(\Zend\Stdlib\RequestInterface $request, \Zend\Stdlib\ResponseInterface $response = null)
 {
     // Fetch client with given ID for actions referring to a particular client
     $action = $this->getEvent()->getRouteMatch()->getParam('action');
     if ($action != 'index' and $action != 'search' and $action != 'import') {
         try {
             $this->_currentClient = $this->_clientManager->getClient($request->getQuery('id'));
         } catch (\RuntimeException $e) {
             // Client does not exist - may happen when URL has become stale.
             $this->flashMessenger()->addErrorMessage('The requested client does not exist.');
             return $this->redirectToRoute('client', 'index');
         }
     }
     return parent::dispatch($request, $response);
 }
 /**
  * Process put data and call update
  *
  * @param Request $request
  * @param $routeMatch
  * @return mixed
  * @throws Exception\DomainException
  */
 public function processPutData(Request $request, $routeMatch)
 {
     if (null === ($id = $routeMatch->getParam('id'))) {
         if (!($id = $request->getQuery()->get('id', false))) {
             throw new Exception\DomainException('Missing identifier');
         }
     }
     $content = $request->getContent();
     parse_str($content, $parsedParams);
     return $this->update($id, $parsedParams);
 }
Beispiel #9
0
 public function setMethod(Request $request, $uri)
 {
     $method = $this->getMethodType($uri);
     $request->getQuery()->set('viewMethod', strtolower($method ?: 'html'));
     $request->getQuery()->set('method', strtoupper($request->getQuery()->get('method') ?: $request->getPost()->get('method') ?: filter_input(INPUT_SERVER, 'REQUEST_METHOD')));
 }
    /**
     * Attempt to retrieve the identifier for a given request
     *
     * Checks first if the $identifierName is in the route matches, and then
     * as a query string parameter.
     *
     * @param string $identifierName
     * @param RouteMatch $routeMatch
     * @param \Zend\Stdlib\RequestInterface $request
     * @return false|mixed
     */
    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);
    }
Beispiel #11
0
 /**
  * Use the composed request to fetch the identity from the query string
  * argument "user_id".
  *
  * @param RequestInterface $requst
  * @return mixed
  */
 public function __invoke(RequestInterface $request)
 {
     return $request->getQuery('user_id', null);
 }
Beispiel #12
0
 /**
  * Support method for init() -- figure out which theme option is active.
  *
  * @param Request $request Request object (for obtaining user parameters).
  *
  * @return string
  */
 protected function pickTheme(Request $request)
 {
     // Load standard configuration options:
     $standardTheme = $this->config->Site->theme;
     $mobileTheme = isset($this->config->Site->mobile_theme) ? $this->config->Site->mobile_theme : false;
     // Find out if the user has a saved preference in the POST, URL or cookies:
     $selectedUI = $request->getPost()->get('ui', $request->getQuery()->get('ui', isset($request->getCookie()->ui) ? $request->getCookie()->ui : null));
     if (empty($selectedUI)) {
         $selectedUI = $mobileTheme && Mobile::detect() ? 'mobile' : 'standard';
     }
     // Save the current setting to a cookie so it persists:
     $_COOKIE['ui'] = $selectedUI;
     setcookie('ui', $selectedUI, null, '/');
     // Do we have a valid mobile selection?
     if ($mobileTheme && $selectedUI == 'mobile') {
         return $mobileTheme;
     }
     // Do we have a non-standard selection?
     if ($selectedUI != 'standard' && isset($this->config->Site->alternate_themes)) {
         // Check the alternate theme settings for a match:
         $parts = explode(',', $this->config->Site->alternate_themes);
         foreach ($parts as $part) {
             $subparts = explode(':', $part);
             if (trim($subparts[0]) == trim($selectedUI) && isset($subparts[1]) && !empty($subparts[1])) {
                 return $subparts[1];
             }
         }
     }
     // If we got this far, we either have a standard option or the user chose
     // an invalid non-standard option; either way, we need to default to the
     // standard theme:
     return $standardTheme;
 }
 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;
 }