From 3adbd3a33719d1131d63812d71df11b6eb52fe12 Mon Sep 17 00:00:00 2001 From: Carles Jove i Buxeda Date: Sun, 13 Jan 2019 16:17:26 +0100 Subject: [PATCH] Dispatch app explicitly --- a.php | 49 ++++++++++++++++++++++++------------------------- index.php | 3 ++- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/a.php b/a.php index 08855c6..5b83cc4 100644 --- a/a.php +++ b/a.php @@ -22,7 +22,29 @@ public function __construct($path) { $this->path = $this->ignore_ending_slash( explode('/', $path) ); $this->layout = $this->as_file($this->layout); - $this->dispatch(); + } + + public function dispatch() { + try { + $this->find_matches(); + + // Include custom functions + if ( file_exists( $this->as_file('functions') ) ) { + include $this->as_file('functions'); + } + + if ( $this->uses_layout() ) { + include $this->global_data(); + if ( $this->is_multilingual() and $this->current_lang ) { + include $this->global_data($this->current_lang); + } + include $this->layout; + } else { + $this->content(); + } + } catch (Exception $e) { + echo $e->getMessage(); + } } protected function find_matches() { @@ -100,29 +122,6 @@ protected function content() { include $this->request; } - protected function dispatch() { - try { - $this->find_matches(); - - // Include custom functions - if ( file_exists( $this->as_file('functions') ) ) { - include $this->as_file('functions'); - } - - if ( $this->uses_layout() ) { - include $this->global_data(); - if ( $this->is_multilingual() and $this->current_lang ) { - include $this->global_data($this->current_lang); - } - include $this->layout; - } else { - $this->content(); - } - } catch (Exception $e) { - echo $e->getMessage(); - } - } - protected function global_data($lang = '') { if ( $lang != '' and file_exists( "data/langs/{$lang}/" . $this->as_file('global') ) ) { return "data/langs/{$lang}/" . $this->as_file('global'); @@ -199,4 +198,4 @@ public function lang($lang) { } } -} \ No newline at end of file +} diff --git a/index.php b/index.php index dfb48f7..6cf99f4 100755 --- a/index.php +++ b/index.php @@ -10,7 +10,8 @@ A::generate_htaccess(); } $path = isset($_GET['path']) ? $_GET['path'] : ''; - new A( $path ); + $a = new A( $path ); + $a->dispatch(); } } else { die("Could not find A");