Skip to content

Commit

Permalink
Dispatch app explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
carlesjove committed Jan 13, 2019
1 parent 4cc6170 commit 3adbd3a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
49 changes: 24 additions & 25 deletions a.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -199,4 +198,4 @@ public function lang($lang) {
}
}

}
}
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 3adbd3a

Please sign in to comment.