Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getRouteCollectionForRequest(Request $request)
 {
     $collection = new RouteCollection();
     $path = $request->getPathInfo();
     $prefix = $this->requestAnalyzer->getResourceLocatorPrefix();
     if (!empty($prefix) && strpos($path, $prefix) === 0) {
         $path = PathHelper::relativizePath($path, $prefix);
     }
     $route = $this->findRouteByPath($path, $request->getLocale());
     if ($route && array_key_exists($route->getId(), $this->symfonyRouteCache)) {
         $collection->add(self::ROUTE_PREFIX . $route->getId(), $this->symfonyRouteCache[$route->getId()]);
         return $collection;
     }
     if (!$route || !$this->routeDefaultsProvider->supports($route->getEntityClass()) || !$this->routeDefaultsProvider->isPublished($route->getEntityClass(), $route->getEntityId(), $route->getLocale())) {
         return $collection;
     }
     $collection->add(self::ROUTE_PREFIX . $route->getId(), $this->createRoute($route, $request));
     return $collection;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function getNode($path)
 {
     $this->assertLoggedIn();
     PathHelper::assertValidAbsolutePath($path, false, true, $this->getNamespacePrefixes());
     $values[':path'] = $path;
     $values[':pathd'] = rtrim($path, '/') . '/%';
     $values[':workspace'] = $this->workspaceName;
     if ($this->fetchDepth > 0) {
         $values[':fetchDepth'] = $this->fetchDepth;
         $query = '
           SELECT * FROM phpcr_nodes
           WHERE (path LIKE :pathd OR path = :path)
             AND workspace_name = :workspace
             AND depth <= ((SELECT depth FROM phpcr_nodes WHERE path = :path AND workspace_name = :workspace) + :fetchDepth)
           ORDER BY depth, sort_order ASC';
     } else {
         $query = '
           SELECT * FROM phpcr_nodes
           WHERE path = :path
             AND workspace_name = :workspace
           ORDER BY depth, sort_order ASC';
     }
     $stmt = $this->getConnection()->executeQuery($query, $values);
     $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     if (empty($rows)) {
         throw new ItemNotFoundException("Item {$path} not found in workspace " . $this->workspaceName);
     }
     $nestedNodes = $this->getNodesData($rows);
     $node = array_shift($nestedNodes);
     foreach ($nestedNodes as $nestedPath => $nested) {
         $relativePath = PathHelper::relativizePath($nestedPath, $path);
         $this->nestNode($node, $nested, explode('/', $relativePath));
     }
     return $node;
 }
Ejemplo n.º 3
0
 /**
  * Returns all route-document which referees given document.
  *
  * @param $document
  * @param $webspaceKey
  *
  * @return array
  */
 protected function findReferrer($document, $webspaceKey)
 {
     $routes = [];
     $referrers = $this->inspector->getReferrers($document);
     foreach ($referrers as $routeDocument) {
         if ($routeDocument instanceof RouteDocument) {
             $path = PathHelper::relativizePath($routeDocument->getPath(), $this->getRoutesPath($webspaceKey));
             $routes[$path] = $routeDocument;
             $tmp = $this->findReferrer($routeDocument, $webspaceKey);
             $routes = array_merge($routes, $tmp);
         }
     }
     return $routes;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function invalidateRoute($webspaceKey, RouteDocument $routeDocument)
 {
     $this->cacheHandler->invalidatePath(PathHelper::relativizePath($routeDocument->getPath(), $this->getRoutesPath($webspaceKey)));
 }
Ejemplo n.º 5
0
 /**
  * @dataProvider dataproviderRelativizePathInvalid
  */
 public function testRelativizePathInvalidNoThrow($inputPath, $context)
 {
     $this->assertFalse(PathHelper::relativizePath($inputPath, $context, false));
 }
Ejemplo n.º 6
0
 /**
  * Add redirect to current custom-url.
  *
  * @param Request $request
  * @param RouteDocument $routeDocument
  * @param RouteCollection $collection
  * @param string $webspaceKey
  *
  * @return RouteCollection
  */
 private function addHistoryRedirectToRouteCollection(Request $request, RouteDocument $routeDocument, RouteCollection $collection, $webspaceKey)
 {
     $resourceSegment = PathHelper::relativizePath($routeDocument->getTargetDocument()->getPath(), $this->getRoutesPath($webspaceKey));
     $url = sprintf('%s://%s', $request->getScheme(), $resourceSegment);
     $collection->add(uniqid('custom_url_route_', true), new Route($request->getPathInfo(), ['_controller' => 'SuluWebsiteBundle:Default:redirect', '_finalized' => true, 'url' => $url]));
     return $collection;
 }