Last active
March 8, 2016 12:11
-
-
Save solleer/eb2b613ce786b3f6e449 to your computer and use it in GitHub Desktop.
Static Router Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Config\Router; | |
class StaticPages implements \Level2\Router\Rule { | |
private $dice; | |
private $static_dir; | |
public function __construct(\Dice\Dice $dice, $static_dir = 'Modules/Static', $layout_xml = 'Layouts/layout.xml') { | |
$this->dice = $dice; | |
$this->static_dir = $static_dir; | |
$this->layout_xml = $layout_xml; | |
} | |
public function find(array $route) { | |
$json_config = json_decode(file_get_contents($this->static_dir . '/static.json'), true); | |
$config = $json_config; | |
foreach ($route as $part) { | |
if (!isset($config[$part])) return false; | |
$config = $config[$part]; | |
} | |
if (empty($config)) return false; | |
$model = (object) $config; | |
$view = $this->dice->create('Transphporm\\Builder', [$this->layout_xml, $this->static_dir . '/static.tss']); | |
return new \Level2\Router\Route($model, $view, NULL, getcwd()); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment