mirror of
https://github.com/openvk/chandler.git
synced 2025-03-31 21:43:59 +03:00
Moving the contants definitions and removing unused code.
This commit is contained in:
parent
ca311a53cc
commit
9bf852d417
4 changed files with 10 additions and 47 deletions
|
@ -8,8 +8,9 @@ preferences:
|
|||
exposeChandler: true
|
||||
|
||||
extensions:
|
||||
path: null
|
||||
allEnabled: false
|
||||
available: "/extensions/available"
|
||||
enabled: "/extensions/enabled"
|
||||
|
||||
database:
|
||||
dsn: "mysql:host=localhost;dbname=db"
|
||||
|
|
|
@ -51,6 +51,6 @@ class Bootstrap
|
|||
{
|
||||
$this->igniteExtensions();
|
||||
header("Referrer-Policy: strict-origin-when-cross-origin");
|
||||
$this->route(function_exists("get_current_url") ? get_current_url() : $_SERVER["REQUEST_URI"]);
|
||||
$this->route($_SERVER["REQUEST_URI"]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,21 +4,14 @@ use Chandler\Classes\Singleton;
|
|||
use Chandler\MVC\Routing\Router;
|
||||
use Nette\Utils\Finder;
|
||||
|
||||
define("CHANDLER_EXTENSIONS", CHANDLER_ROOT_CONF["extensions"]["path"] ?? CHANDLER_ROOT . "/extensions", false);
|
||||
define("CHANDLER_EXTENSIONS_AVAILABLE", CHANDLER_EXTENSIONS . "/available", false);
|
||||
|
||||
if(CHANDLER_ROOT_CONF["extensions"]["allEnabled"]) {
|
||||
define("CHANDLER_EXTENSIONS_ENABLED", CHANDLER_EXTENSIONS_AVAILABLE, false);
|
||||
} else {
|
||||
define("CHANDLER_EXTENSIONS_ENABLED", CHANDLER_EXTENSIONS . "/enabled", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Chandler\Extensions
|
||||
*/
|
||||
class ExtensionManager extends Singleton
|
||||
{
|
||||
private $extensions = [];
|
||||
private $router = NULL;
|
||||
private $rootApp = NULL;
|
||||
private $eventLoop = NULL;
|
||||
private $router;
|
||||
private $rootApp;
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
|
@ -66,11 +59,6 @@ class ExtensionManager extends Singleton
|
|||
private function init(): void
|
||||
{
|
||||
foreach($this->getExtensions(true) as $name => $configuration) {
|
||||
spl_autoload_register(@create_function("\$class", "
|
||||
if(!substr(\$class, 0, " . iconv_strlen("$name\\") . ") === \"$name\\\\\") return false;
|
||||
|
||||
include_once CHANDLER_EXTENSIONS_ENABLED . \"/\" . str_replace(\"\\\\\", \"/\", \$class) . \".php\";
|
||||
"));
|
||||
|
||||
define(str_replace("-", "_", mb_strtoupper($name)) . "_ROOT", CHANDLER_EXTENSIONS_ENABLED . "/$name", false);
|
||||
define(str_replace("-", "_", mb_strtoupper($name)) . "_ROOT_CONF", chandler_parse_yaml(CHANDLER_EXTENSIONS_ENABLED . "/$name/$name.yml"), false);
|
||||
|
@ -81,15 +69,6 @@ class ExtensionManager extends Singleton
|
|||
$init();
|
||||
}
|
||||
|
||||
if(is_dir($hooks = CHANDLER_EXTENSIONS_ENABLED . "/$name/Hooks")) {
|
||||
foreach(Finder::findFiles("*Hook.php")->in($hooks) as $hookFile) {
|
||||
$hookClassName = "$name\\Hooks\\" . str_replace(".php", "", end(explode("/", $hookFile)));
|
||||
$hook = new $hookClassName;
|
||||
|
||||
$this->eventLoop->addListener($hook);
|
||||
}
|
||||
}
|
||||
|
||||
if(is_dir($app = CHANDLER_EXTENSIONS_ENABLED . "/$name/Web")) #"app" means "web app", thus variable is called $app
|
||||
$this->router->readRoutes("$app/routes.yml", $name, $this->rootApp !== $name);
|
||||
}
|
||||
|
@ -106,23 +85,4 @@ class ExtensionManager extends Singleton
|
|||
{
|
||||
return @$this->extensions[$name];
|
||||
}
|
||||
|
||||
function disableExtension(string $name): void
|
||||
{
|
||||
if(!array_key_exists($name, $this->getExtensions(true))) return;
|
||||
|
||||
if(!unlink(CHANDLER_EXTENSIONS_ENABLED . "/$name")) throw new \Exception("Could not disable extension");
|
||||
}
|
||||
|
||||
function enableExtension(string $name): void
|
||||
{
|
||||
if(CHANDLER_ROOT_CONF["extensions"]["allEnabled"]) return;
|
||||
|
||||
if(array_key_exists($name, $this->getExtensions(true))) return;
|
||||
|
||||
$path = CHANDLER_EXTENSIONS_AVAILABLE . "/$name";
|
||||
if(!is_dir($path)) throw new \Exception("Extension doesn't exist");
|
||||
|
||||
if(!symlink($path, str_replace("available", "enabled", $path))) throw new \Exception("Could not enable extension");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ require_once(dirname(__DIR__) . "/vendor/autoload.php");
|
|||
|
||||
define("CHANDLER_ROOT", dirname(__DIR__));
|
||||
define("CHANDLER_ROOT_CONF", yaml_parse_file(CHANDLER_ROOT . "/chandler.yml"));
|
||||
define("CHANDLER_EXTENSIONS_AVAILABLE", CHANDLER_ROOT . CHANDLER_ROOT_CONF["extensions"]["available"]);
|
||||
define("CHANDLER_EXTENSIONS_ENABLED", CHANDLER_ROOT . CHANDLER_ROOT_CONF["extensions"]["enabled"]);
|
||||
|
||||
$bootstrap = new Bootstrap();
|
||||
|
||||
|
|
Loading…
Reference in a new issue