示例#1
0
<?php

use Micro\Application\Application;
use Micro\Application\Utils;
$config = [];
foreach (glob('{application/config/*.php,application/config/packages/*.php}', GLOB_BRACE) as $file) {
    $config = Utils::merge($config, include $file);
}
if (isset($config['packages'])) {
    MicroLoader::addPath($config['packages']);
}
$app = new Application($config);
$app->registerDefaultServices();
$app->get('router')->mapFromConfig()->loadDefaultRoutes();
return $app;
示例#2
0
 /**
  * Boot the application
  * @throws CoreException
  * @return Application
  */
 public function boot()
 {
     if (\true === $this->booted) {
         return $this;
     }
     $modules = $this->container->get('config')->get('modules', []);
     \MicroLoader::addPath($modules);
     foreach ($modules as $module => $path) {
         $moduleInstance = $module . '\\Module';
         if (\class_exists($moduleInstance, \true)) {
             $instance = new $moduleInstance($this->container);
             if (!$instance instanceof Module) {
                 throw new CoreException(\sprintf('%s must be instance of Micro\\Application\\Module', $moduleInstance), 500);
             }
             $instance->boot($this->container);
             $this->modules[$module] = $instance;
             continue;
         }
         throw new CoreException(sprintf('[' . __METHOD__ . '] Module [%s] is loaded but class [%s\\Module] is missing', $module, $module));
     }
     $this->booted = \true;
     return $this;
 }