Example #1
0
 public function detect(DetectorConfig $config, RequestInterface $request)
 {
     $domains = $config->getDomains();
     $host = $request->getUri()->getHost();
     $matched = null;
     if (null === $domains || empty($domains)) {
         throw new Exception\InvalidArgumentException('No domains where configured');
     }
     foreach ($domains as $domain) {
         if (strpos($domain, self::LOCALE_KEY) === false) {
             throw new Exception\InvalidArgumentException(sprintf('The domain %s must contain a locale key part "%s"', $domain, self::LOCALE_KEY));
         }
         $pattern = str_replace(self::LOCALE_KEY, '([a-zA-Z-_.]+)', $domain);
         $pattern = sprintf('@%s@', $pattern);
         $result = preg_match($pattern, $host, $matches);
         if ($result) {
             $matched = $matches;
         }
     }
     $locale = $matched[1];
     $aliases = $config->getAliases();
     if (null !== $aliases && array_key_exists($locale, $aliases)) {
         $locale = $aliases[$locale];
     }
     return $locale;
 }
Example #2
0
 /**
  * @param  string               $name               Name of the route
  * @param  array                $params             Parameters for the link
  * @param  array|Traversable    $options            Options for the route
  * @param  bool                 $reuseMatchedParams Whether to reuse matched parameters
  * @return string Url                         For the link href attribute
  */
 public function __invoke($name = null, $params = [], $options = [], $reuseMatchedParams = false)
 {
     $referer = $this->request->getHeader('Referer');
     if ($referer) {
         $refererUrl = $referer->uri()->getPath();
         // referer url
         $refererHost = $referer->uri()->getHost();
         // referer host
         $host = $this->request->getUri()->getHost();
         // current host
         // only redirect to previous page if request comes from same host
         if ($refererUrl && $refererHost == $host) {
             return $refererUrl;
         }
     }
     // redirect to home if no referer or from another page
     return $this->view->url($name, $params, $options, $reuseMatchedParams);
 }
Example #3
0
 /**
  * Match a given request. Run Symfony if it wants the route.
  *
  * @param  Request $request
  * @return RouteMatch|null
  */
 public function match(Request $request)
 {
     try {
         self::$routeCollection->match($request->getUri()->getPath());
     } catch (ResourceNotFoundException $e) {
         return null;
     }
     $dispatcher = new SymfonyDispatcher();
     $dispatcher->dispatchRouteToSymfony();
 }
Example #4
0
 public function detect(DetectorConfig $config, RequestInterface $request)
 {
     $base = $this->getBasePath();
     $locale = $this->getFirstSegmentInPath($request->getUri(), $base);
     $aliases = $config->getAliases();
     if (null !== $aliases && array_key_exists($locale, $aliases)) {
         $locale = $aliases[$locale];
     }
     return $locale;
 }
Example #5
0
 /**
  * @param RequestInterface $request
  *
  * @return bool
  */
 public function isAllowed(RequestInterface $request)
 {
     if (!$request instanceof Http\Request) {
         return false;
     }
     if ($this->authService->hasIdentity()) {
         return true;
     }
     $path = $request->getUri()->getPath();
     return in_array($path, ['', '/']);
 }
Example #6
0
 /**
  * Match a given request.
  *
  * @param  Request $request
  * @return RouteMatch|null
  */
 public function match(Request $request)
 {
     try {
         //This line is odd but prevents a warning
         //            self::$routeCollection->request = $request;
         $params = self::$routeCollection->match($request->getUri()->getPath());
     } catch (ResourceNotFoundException $e) {
         return null;
     }
     $dispatcher = new SymfonyDispatcher();
     $dispatcher->dispatchRouteToSymfony($params);
 }
Example #7
0
 /**
  * Match a given request.
  *
  * @param RequestInterface $request
  * @param int $pathOffset
  * @return null|RouteMatch|\Zend\Mvc\Router\RouteMatch
  */
 public function match(RequestInterface $request, $pathOffset = null)
 {
     /** @var string $path */
     $path = trim(substr($request->getUri()->getPath(), $pathOffset), '/');
     /** @var \Msingi\Cms\Entity\Page $page */
     $page = $this->loadPage($path);
     if ($page == null) {
         return null;
     }
     /** @var array $routeParams */
     $routeParams = array_merge($this->defaults, array('cms_page' => $page, 'path' => $page->getPath()));
     $routeMatch = new RouteMatch($routeParams, strlen($page->getPath()));
     return $routeMatch;
 }
Example #8
0
 public function match(RequestInterface $request, $pathOffset = 0)
 {
     if (!$request instanceof HttpRequest) {
         return;
     }
     $virtualUrl = substr($request->getUri()->getPath(), $pathOffset);
     if (!isset($virtualUrl[0]) || $virtualUrl[0] !== '/') {
         return;
     }
     if (!($page = $this->urlMapper->findByUrl(substr($virtualUrl, 1)))) {
         return;
     }
     $this->assembledParams = ['page' => $page];
     return new RouteMatch(['page' => $page, 'controller' => UrlController::class, 'action' => 'index'], strlen($virtualUrl));
 }
Example #9
0
 /**
  * @inheritdoc
  */
 public function match(Request $request)
 {
     /** @var \Zend\Http\Request $request */
     $path = $request->getUri()->getPath();
     $segments = preg_split('@/@', $path);
     if (count($segments) < 1) {
         return false;
     }
     $id = array_pop($segments);
     $className = trim(implode('\\', $segments), '\\');
     if (!class_exists($className)) {
         return false;
     }
     $routeMatch = new RouteMatch(['id' => $id, 'className' => $className, '_isNakedObject' => true, 'controller' => 'NakedObjectController']);
     return $routeMatch;
 }
Example #10
0
 /**
  * Dispatch a request
  *
  * @events dispatch.pre, dispatch.post
  * @param  Request $request
  * @param  null|Response $response
  * @return Response|mixed
  */
 public function dispatch(Request $request, Response $response = null)
 {
     if ($this->requiredLogin) {
         $user = $this->getCurrentUser();
         if (!$user) {
             $msg = $this->getTranslator()->translate("You must login in order to process this page.");
             $this->flashMessenger()->addErrorMessage($msg);
             /** @var \Zend\Uri\Http $url */
             $uri = $request->getUri();
             $langArr = explode('/', $uri->getPath());
             $lang = $langArr[1];
             $requestUri = $uri->getPath() . ($uri->getQuery() ? "?" . $uri->getQuery() : "");
             $requestUriArr = explode('/', $requestUri);
             unset($requestUriArr[1]);
             $requestUri = implode($requestUriArr, '/');
             return $this->redirect()->toUrl("/{$lang}/user/login?next=" . $requestUri);
         }
     }
     return parent::dispatch($request, $response);
 }
Example #11
0
File: Cms.php Project: reliv/Rcm
 /**
  * match
  *
  * @param RequestInterface $request
  * @param int              $pathOffset
  *
  * @return bool|null|RouteMatch
  */
 public function match(RequestInterface $request, $pathOffset = 0)
 {
     if (!$request instanceof Request) {
         return null;
     }
     $pageUrl = substr($request->getUri()->getPath(), $pathOffset);
     $type = $this->getPageType();
     $pageParams = $this->parseUrl($pageUrl);
     if (empty($pageParams)) {
         return null;
     }
     try {
         $page = $this->getPage($pageParams['pageName'], $type);
     } catch (\Exception $e) {
         return null;
     }
     if (empty($page)) {
         return false;
     }
     $cms_params = array('page' => $page, 'controller' => $this->getController($type), 'action' => $this->getAction($type), 'revision' => $pageParams['revision']);
     return new RouteMatch($cms_params, strlen($pageUrl));
 }
Example #12
0
 /**
  * Resolve the request to a file.
  *
  * @param RequestInterface $request
  *
  * @return mixed false when not found, AssetInterface when resolved.
  */
 protected function resolve(RequestInterface $request)
 {
     if (!$request instanceof Request) {
         return false;
     }
     /* @var $request Request */
     /* @var $uri \Zend\Uri\UriInterface */
     $uri = $request->getUri();
     $fullPath = $uri->getPath();
     $path = substr($fullPath, strlen($request->getBasePath()) + 1);
     $this->path = $path;
     $asset = $this->getResolver()->resolve($path);
     if (!$asset instanceof AssetInterface) {
         return false;
     }
     return $asset;
 }
 public function __construct(Request $request, array $parts)
 {
     $this->path = $request->getUri()->getPath();
     array_map(array($this, 'addPart'), $parts);
 }