Skip to content

Commit

Permalink
Always load routes
Browse files Browse the repository at this point in the history
  • Loading branch information
giuscris committed Oct 24, 2019
1 parent d774340 commit dbfa9e7
Showing 1 changed file with 35 additions and 46 deletions.
81 changes: 35 additions & 46 deletions formwork/Core/Formwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ class Formwork
*/
protected $cache;

/**
* Current page cache key
*
* @var string
*/
protected $cacheKey;

/**
* Create a new Formwork instance
*/
Expand All @@ -100,8 +93,7 @@ public function __construct()
$this->loadLanguages();
$this->loadSite();
$this->loadCache();

$this->router = new Router($this->request);
$this->loadRoutes();
}

/**
Expand Down Expand Up @@ -216,26 +208,7 @@ public function defaults()
*/
public function run()
{
$isTrackable = false;

if ($this->option('cache.enabled') && $this->cache->has($this->cacheKey)) {
$resource = $this->cache->fetch($this->cacheKey);
} else {
if ($this->option('admin.enabled')) {
$this->loadAdminRoute();
}

$this->router->add(array(
'/',
'/page/{paginationPage:num}/',
'/{page}/tag/{tagName:aln}/page/{paginationPage:num}/',
'/{page}/tag/{tagName:aln}/',
'/{page}/page/{paginationPage:num}/',
'/{page}/'
), $this->defaultRoute());

$resource = $this->router->dispatch();
}
$resource = $this->router->dispatch();

if ($resource instanceof Page) {
if (is_null($this->site->currentPage())) {
Expand All @@ -244,15 +217,14 @@ public function run()

$page = $this->site->currentPage();

$content = $page->render();

if (!$page->isErrorPage()) {
$isTrackable = true;
}
if ($this->option('cache.enabled') && $this->cache->has($page->route())) {
$response = $this->cache->fetch($page->route());
$response->render();
} else {
$content = $page->render();

if ($this->option('cache.enabled')) {
if ($page->cacheable()) {
$this->cache->save($this->cacheKey, new Response(
if ($this->option('cache.enabled') && $page->cacheable()) {
$this->cache->save($page->route(), new Response(
$content,
$page->get('response_status'),
$page->headers()
Expand All @@ -261,14 +233,11 @@ public function run()
}
}

if ($resource instanceof Response) {
$resource->render();
$isTrackable = true;
}

if ($this->option('statistics.enabled') && $isTrackable) {
$statistics = new Statistics();
$statistics->trackVisit();
if ($this->option('statistics.enabled')) {
if (isset($page) && !$page->isErrorPage()) {
$statistics = new Statistics();
$statistics->trackVisit();
}
}
}

Expand Down Expand Up @@ -333,10 +302,30 @@ protected function loadCache()
{
if ($this->option('cache.enabled')) {
$this->cache = new SiteCache($this->option('cache.path'), $this->option('cache.time'));
$this->cacheKey = Uri::normalize(HTTPRequest::uri());
}
}

/**
* Load routes
*/
protected function loadRoutes()
{
$this->router = new Router($this->request);

if ($this->option('admin.enabled')) {
$this->loadAdminRoute();
}

$this->router->add(array(
'/',
'/page/{paginationPage:num}/',
'/{page}/tag/{tagName:aln}/page/{paginationPage:num}/',
'/{page}/tag/{tagName:aln}/',
'/{page}/page/{paginationPage:num}/',
'/{page}/'
), $this->defaultRoute());
}

/**
* Load admin route
*/
Expand Down

0 comments on commit dbfa9e7

Please sign in to comment.