Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
PageViewer
- Dylan
*/
namespace ExcellentCode;
final class PageViewer {
protected $_path, $_config;
public function __construct($path = "404", $config) {
if(count($config["pages"]) == 0) throw new Exception("No pages defined");
$this->_path = $path;
$this->_config = $config;
$this->_lookUp();
}
protected function _lookUp() {
if(isset($this->_config["pages"][$this->_path])) {
if(is_array($this->_config["pages"][$this->_path]) &&
isset($this->_config["pages"][$this->_path]["controller"]) &&
isset($this->_config["pages"][$this->_path]["url"])) {
if(file_exists(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php") &&
is_readable(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php")) {
require_once(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php");
$controller = "ExcellentCodeControllers" . $this->_config["pages"][$this->_path]["controller"];
$controller = new $controller();
$controller->renderTemplate($this->_config["pages"][$this->_path]["url"]);
return;
}
include_once(ABS_PATH . "/pages/404.html");
return;
return;
} else {
$page = (isset($this->_config["pages"][$this->_path]["url"]) ?
$this->_config["pages"][$this->_path]["url"] :
$this->_config["pages"][$this->_path]
);
if(file_exists(ABS_PATH . "/pages/{$page}") &&
is_readable(ABS_PATH . "/pages/{$page}")
) {
include_once(ABS_PATH . "/pages/{$page}");
return;
}
}
}
include_once(ABS_PATH . "/pages/404.html");
return;
}
}
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
- controller class
dylan
*/
namespace ExcellentCode;
interface ControllerInterface {
public function setModels();
}
abstract class Controller {
public $models;
final public function __construct() {
if(method_exists($this, "__begin")) $this->__begin();
$this->setModels();
}
final protected function set($key, $val) {
$this->models[$key] = $val;
}
final public function renderTemplate($templateFile) {
if(file_exists(ABS_PATH . "/pages/{$templateFile}") &&
is_readable(ABS_PATH . "/pages/{$templateFile}")) {
$content = file_get_contents(ABS_PATH . "/pages/{$templateFile}");
foreach ($this->models as $key => $value) {
$content = str_replace("{{".$key."}}", $value, $content);
}
echo $content;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
PageViewer
- Dylan
*/
namespace ExcellentCode;
final class PageViewer {
protected $_path, $_config;
public function __construct($path = "404", $config) {
if(count($config["pages"]) == 0) throw new Exception("No pages defined");
$this->_path = $path;
$this->_config = $config;
$this->_lookUp();
}
protected function _lookUp() {
if(isset($this->_config["pages"][$this->_path])) {
if(is_array($this->_config["pages"][$this->_path]) &&
isset($this->_config["pages"][$this->_path]["controller"]) &&
isset($this->_config["pages"][$this->_path]["url"])) {
if(file_exists(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php") &&
is_readable(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php")) {
require_once(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php");
$controller = "ExcellentCodeControllers" . $this->_config["pages"][$this->_path]["controller"];
$controller = new $controller();
$controller->renderTemplate($this->_config["pages"][$this->_path]["url"]);
return;
}
include_once(ABS_PATH . "/pages/404.html");
return;
return;
} else {
$page = (isset($this->_config["pages"][$this->_path]["url"]) ?
$this->_config["pages"][$this->_path]["url"] :
$this->_config["pages"][$this->_path]
);
if(file_exists(ABS_PATH . "/pages/{$page}") &&
is_readable(ABS_PATH . "/pages/{$page}")
) {
include_once(ABS_PATH . "/pages/{$page}");
return;
}
}
}
include_once(ABS_PATH . "/pages/404.html");
return;
}
}
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
- controller class
dylan
*/
namespace ExcellentCode;
interface ControllerInterface {
public function setModels();
}
abstract class Controller {
public $models;
final public function __construct() {
if(method_exists($this, "__begin")) $this->__begin();
$this->setModels();
}
final protected function set($key, $val) {
$this->models[$key] = $val;
}
final public function renderTemplate($templateFile) {
if(file_exists(ABS_PATH . "/pages/{$templateFile}") &&
is_readable(ABS_PATH . "/pages/{$templateFile}")) {
$content = file_get_contents(ABS_PATH . "/pages/{$templateFile}");
foreach ($this->models as $key => $value) {
$content = str_replace("{{".$key."}}", $value, $content);
}
echo $content;
}
}
}








