Exemplo n.º 1
0
 /**
  * Get a singleton app object
  *
  * @param string $name
  *            Name of app instance to get
  *
  * @return \Core\Framework\Amvc\App\AbstractApp
  */
 public function &getAppInstance(string $name)
 {
     if (empty($name)) {
         throw new FrameworkException('Core::getAppInstance() needs an app name');
     }
     $string = new CamelCase($name);
     $name = $string->camelize();
     // App instances are singletons!
     if (!array_key_exists($name, $this->apps)) {
         // Create class name
         $class = '\\Apps\\' . $name . '\\' . $name;
         //
         $filename = $this->basedir . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
         if (!file_exists($filename)) {
             throw new FrameworkException(sprintf('Apps could not find an app classfile "%s" for app "%s"', $name, $filename));
         }
         // Default arguments for each app instance
         $args = [$name, $this->config->createStorage($name), $this];
         $instance = $this->di->instance($class, $args);
         if (!$instance instanceof AbstractApp) {
             throw new FrameworkException('Apps must be an instance of AbstractApp class!');
         }
         $instance->setName($name);
         $instance->language->setCode($this->config->get('Core', 'site.language.default'));
         $this->apps[$name] = $instance;
     }
     return $this->apps[$name];
 }
Exemplo n.º 2
0
use core\Database\Database;
use core\View\Builder;
use core\DI\DI;
use core\Http\Request;
use core\Session\SessionManager as Session;
require_once 'Config.php';
require_once 'Autoloader.php';
/*
 * System init
 */
date_default_timezone_set(Config::get('app')['timezone']);
setlocale(LC_ALL, Config::get('app')['locale']);
/*
 * Dependency injection init
 */
$di = new DI();
/*
 * Builder init
 */
$di->set('builder', new Builder('Smarty', 'layout/layout.tpl'))->setConfig(Config::get('builder'));
if (isset(Config::get('builder')['fe_javascripts'])) {
    $di->get('builder')->setJavaScript(Config::get('builder')['fe_javascripts']);
}
if (isset(Config::get('builder')['fe_css'])) {
    $di->get('builder')->setCSS(Config::get('builder')['fe_css']);
}
$di->get('builder')->assign("cabinet", Config::get('app')['cabinet']);
/*
 * Config init
 */
$di->set('config', new Config());