public static function preExecute($actions) { $request = $actions->getRequest(); // Figure out where we are all over again, because there seems to be no clean way // to get the same controller-free URL that the routing engine gets. TODO: // ask Fabien how we can do that. $uri = $actions->getRequest()->getUri(); $uriPrefix = $actions->getRequest()->getUriPrefix(); $uri = substr($uri, strlen($uriPrefix)); if (preg_match("/^\\/[^\\/]+\\.php(.*)\$/", $uri, $matches)) { $uri = $matches[1]; } // This will quickly fetch a result that was already cached when we // ran through the routing table (unless we hit the routing table cache, // in which case we're looking it up for the first time, also OK) $page = aPageTable::getMatchingEnginePage($uri, $remainder); if (!$page) { throw new sfException('Attempt to access engine action without a page'); } $page = aPageTable::retrieveByIdWithSlots($page->id); // We want to do these things the same way executeShow would aTools::validatePageAccess($actions, $page); aTools::setPageEnvironment($actions, $page); // Convenient access to the current page for the subclass $actions->page = $page; }
/** * Returns the portion of the URL after the engine page slug, or false if there * is no engine page matching the URL. As a special case, if the URL exactly matches the slug, * / is returned. * * @param string $url The URL * * @return string The remainder of the URL */ public static function removePageFromUrl(sfRoute $route, $url) { $remainder = false; // Modifies $remainder if it returns a matching page $page = aPageTable::getMatchingEnginePage($url, $remainder); if (!$page) { return false; } // Engine pages can't have subpages, so if the longest matching path for any engine page // has the wrong engine type for this route, this route definitely doesn't match $defaults = $route->getDefaults(); if ($page->engine !== $defaults['module']) { return false; } // Allows aRoute URLs to be written like ordinary URLs rather than // specifying an empty URL, which seems prone to lead to incompatibilities // Remainder comes back as false, not '', for an exact match if (!strlen($remainder)) { $remainder = '/'; } return $remainder; }