Пример #1
0
 /**
  * Load a module
  *
  * @param string $path path of module
  */
 public static function load($path)
 {
     $basePath = basename($path);
     if (!empty(self::$list[$basePath])) {
         return;
     }
     self::$list[$basePath] = $path;
     if (file_exists($path . '/boot.php')) {
         include $path . '/boot.php';
     }
     $files = self::getAllFiles($path . "/Controller");
     foreach ($files as $file) {
         self::$files[] = $file;
         require_once $file;
         $name_class = str_replace(PATH_SRC, "", $file);
         $name_class = str_replace("/", "\\", $name_class);
         $name_class = str_replace(".php", "", $name_class);
         if (is_subclass_of($name_class, Controller::class)) {
             $reflectionClass = new \ReflectionClass($name_class);
             if ($reflectionClass->IsInstantiable()) {
                 self::$controllers[] = new $name_class();
             }
         }
     }
     $files = self::getAllFiles($path . "/Command");
     foreach ($files as $file) {
         $ext = pathinfo($file, PATHINFO_EXTENSION);
         if ($ext == 'php') {
             self::$files[] = $file;
             require_once $file;
             $name_class = str_replace(PATH_SRC, "", $file);
             $name_class = str_replace("/", "\\", $name_class);
             $name_class = str_replace(".php", "", $name_class);
             if (is_subclass_of($name_class, Command::class)) {
                 Console::addCommand($name_class);
             }
         }
     }
     if (file_exists($path . "/Exceptions/Handler.php")) {
         $name_class = str_replace(PATH_SRC, "", $path . "/Exceptions/Handler.php");
         $name_class = str_replace("/", "\\", $name_class);
         $name_class = str_replace(".php", "", $name_class);
         if (is_subclass_of($name_class, \Kernel\Exceptions\ExceptionHandler::class)) {
             \Kernel\Exceptions\Handler::add($name_class);
         }
     }
     $files = self::getAllFiles($path . "/Service");
     foreach ($files as $file) {
         self::$files[] = $file;
         require_once $file;
         $name_class = str_replace(PATH_SRC, "", $file);
         $name_class = str_replace("/", "\\", $name_class);
         $name_class = str_replace(".php", "", $name_class);
         if (is_subclass_of($name_class, Service::class)) {
             $last_name = explode("\\", $name_class);
             $last_name = end($last_name);
             class_alias($name_class, $last_name);
         }
     }
     if (!file_exists(PATH . "/src/")) {
         mkdir(PATH . "/src", 0755);
     }
     # Create symlink to access
     if (!file_exists(PATH . "/src/" . $basePath)) {
         if (file_exists(PATH . "/../src/" . $basePath . "/Resources/public/")) {
             try {
                 symlink(PATH . "/../src/" . $basePath . "/Resources/public/", PATH . "/src/" . $basePath);
             } catch (\Exception $e) {
                 throw new \Exception($e);
             }
         }
     }
     # Set config
     foreach (glob($path . '/Resources/config/*') as $file) {
         $cfgs = (require_once $file);
         $base = basename($file, ".php");
         foreach ($cfgs as $cfg_name => $cfg_value) {
             Cfg::set($base . "." . $cfg_name, $cfg_value);
         }
     }
 }
Пример #2
0
define('PATH_CONFIG', DIR . '../config');
include DIR . "../vendor/autoload.php";
class_alias("Kernel\\Service", "Service");
class_alias("CoreWine\\Component\\Bag", "Bag");
class_alias("CoreWine\\Component\\Collection", "Collection");
class_alias("CoreWine\\Http\\Flash", "Flash");
class_alias("CoreWine\\Http\\Request", "Request");
class_alias("CoreWine\\Http\\Response\\Response", "Response");
class_alias("CoreWine\\Component\\Cache", "Cache");
class_alias("CoreWine\\Component\\Cfg", "Cfg");
# Make dir cache if doesn't exists
# Add cache dir
Cache::setDir(PATH_APP . '/cache/data');
# Initialize Handler
Handler::register();
Handler::add(\Kernel\Exceptions\ExceptionHandler::class);
# Initialize request
Request::ini();
# Initialize config
$config = (include PATH_CONFIG . '/app.php');
Cfg::add("app", $config);
\CoreWine\View\Engine::ini(PATH_APP . "/cache/views");
\CoreWine\DataBase\DB::connect($config['database']);
# Compile
\CoreWine\View\Engine::compile(PATH_APP, 'Resources/views');
foreach (\Kernel\Manager::$list as $name => $dir) {
    \CoreWine\View\Engine::compile(PATH_APP, "Resources/" . $name . "/views", $name);
}
\CoreWine\DataBase\ORM\SchemaBuilder::setFields(include PATH_CONFIG . '/orm.php');
# Load all sources
\Kernel\Manager::loadAll(PATH_SRC);