Skip to content

Commit

Permalink
#345 - Implement static file router
Browse files Browse the repository at this point in the history
  • Loading branch information
johanjanssens committed May 16, 2020
1 parent e637b59 commit 9cfc9eb
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
60 changes: 60 additions & 0 deletions code/site/components/com_pages/dispatcher/router/file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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
*/

class ComPagesDispatcherRouterFile extends ComPagesDispatcherRouterAbstract
{
protected function _initialize(KObjectConfig $config)
{
$config->append([
'routes' => []
])->append([
'resolvers' => [
'regex' => ['routes' => $config->routes]
]
]);

parent::_initialize($config);
}

public function resolve($route = null, array $parameters = array())
{
$result = false;
if(count($this->getConfig()->routes))
{
if(!$route)
{
$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), '/');
}

$result = parent::resolve($route, $parameters);
}

return $result;
}

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

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

return $url;
}
}
6 changes: 3 additions & 3 deletions code/site/components/com_pages/resources/config/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
'cache_force' => $config['http_resource_cache_force'],
'debug' => $config['http_resource_cache_debug'],
],
'com://site/pages.model.cache' => [
'cache_path' => $config['http_cache_path'],
]
'com://site/pages.dispatcher.router.file' => [
'routes' => isset($config['files']) ? $config['files'] : array(),
],
],
'extensions' => $config['extensions'] ?? array(),
];

0 comments on commit 9cfc9eb

Please sign in to comment.