Skip to content

Commit

Permalink
#345 - Implement specialised file route
Browse files Browse the repository at this point in the history
A file route is absolute if the path of the route is a fully qualified file path
  • Loading branch information
johanjanssens committed May 16, 2020
1 parent 690e7e3 commit 8b0d487
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
24 changes: 12 additions & 12 deletions code/site/components/com_pages/dispatcher/router/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ComPagesDispatcherRouterFile extends ComPagesDispatcherRouterAbstract
protected function _initialize(KObjectConfig $config)
{
$config->append([
'route' => 'file',
'routes' => []
])->append([
'resolvers' => [
Expand All @@ -25,15 +26,15 @@ protected function _initialize(KObjectConfig $config)
public function resolve($route = null, array $parameters = array())
{
$result = false;
if(count($this->getConfig()->routes))
if (count($this->getConfig()->routes))
{
if(!$route)
if (!$route)
{
$base = $this->getRequest()->getBasePath();
$url = urldecode( $this->getRequest()->getUrl()->getPath());
$base = $this->getRequest()->getBasePath();
$url = urldecode($this->getRequest()->getUrl()->getPath());
$parameters = $this->getRequest()->getUrl()->getQuery(true);

$route = trim(str_replace(array($base, '/index.php'), '', $url), '/');
$route = trim(str_replace(array($base, '/index.php'), '', $url), '/');
}

$result = parent::resolve($route, $parameters);
Expand All @@ -42,17 +43,16 @@ public function resolve($route = null, array $parameters = array())
return $result;
}

public function qualify(ComPagesDispatcherRouterRouteInterface $route, $replace = false)
public function qualify(ComPagesDispatcherRouterRouteInterface $route, $replace = false)
{
$url = clone $route;

$path = $url->getPath();
if(!is_file($path))
if(!$url->isAbsolute())
{
//Qualify the path
$path = trim($path, '/');
$base = $this->getRequest()->getBasePath(true);
$url->setPath($base.'/'.$path);
$base = $this->getRequest()->getBasePath(true);
$path = trim($url->getPath(), '/');

$url->setPath($base . '/' . $path);
}

return $url;
Expand Down
22 changes: 22 additions & 0 deletions code/site/components/com_pages/dispatcher/router/route/file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Joomlatools Pages
*
* @copyright Copyright (C) 2018 Johan Janssens and Timble CVBA. (http://www.timble.net)
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository
*/

/**
* Router File Route
*
* @author Johan Janssens <https://github.com/johanjanssens>
* @package Koowa\Library\Dispatcher\Router\Route
*/
class ComPagesDispatcherRouterRouteFile extends ComPagesDispatcherRouterRouteAbstract
{
public function isAbsolute()
{
return file_exists($this->getPath());
}
}

0 comments on commit 8b0d487

Please sign in to comment.