A super easy PHP Framework for web development!
https://github.com/exacti/phacil-framework
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.3 KiB
70 lines
1.3 KiB
<?php
|
|
/*
|
|
* Copyright © 2021 ExacTI Technology Solutions. All rights reserved.
|
|
* GPLv3 General License.
|
|
* https://exacti.com.br
|
|
* Phacil PHP Framework - https://github.com/exacti/phacil-framework
|
|
*/
|
|
|
|
namespace Phacil\Framework;
|
|
|
|
final class Front {
|
|
protected $registry;
|
|
protected $pre_action = array();
|
|
protected $error;
|
|
|
|
public function __construct($registry) {
|
|
$this->registry = $registry;
|
|
}
|
|
|
|
public function addPreAction($pre_action) {
|
|
$this->pre_action[] = $pre_action;
|
|
}
|
|
|
|
public function dispatch($action, $error) {
|
|
$this->error = $error;
|
|
|
|
foreach ($this->pre_action as $pre_action) {
|
|
$result = $this->execute($pre_action);
|
|
|
|
if ($result) {
|
|
$action = $result;
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
while ($action) {
|
|
$action = $this->execute($action);
|
|
}
|
|
}
|
|
|
|
private function execute($action) {
|
|
$file = $action->getFile();
|
|
$class = $action->getClass();
|
|
$method = $action->getMethod();
|
|
$args = $action->getArgs();
|
|
|
|
$action = '';
|
|
|
|
if (file_exists($file)) {
|
|
require_once($file);
|
|
|
|
$controller = new $class($this->registry);
|
|
|
|
if (is_callable(array($controller, $method))) {
|
|
$action = call_user_func_array(array($controller, $method), $args);
|
|
} else {
|
|
$action = $this->error;
|
|
|
|
$this->error = '';
|
|
}
|
|
} else {
|
|
$action = $this->error;
|
|
|
|
$this->error = '';
|
|
}
|
|
|
|
return $action;
|
|
}
|
|
}
|
|
|