/** * 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 AppHandlerException('AppHandler::getAppInstance() method needs a camelized appname.'); } $string = new CamelCase($name); $name = $string->camelize(); // App instances are singletons! if (!array_key_exists($name, $this->instances)) { // Create class name $class = '\\AppHandler\\' . $name . '\\' . $name; // $filename = BASEDIR . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; if (!file_exists($filename)) { throw new AppHandlerException(sprintf('AppHandler could not find an app classfile "%s" for app "%s"', $name, $filename)); } // Default arguments for each app instance $args = [$name, $this, $this->config->getStorage($name), 'core.page', 'core.di']; $instance = $this->di->instance($class, $args); if (!$instance instanceof AbstractApp) { throw new AppHandlerException('AppHandler must be an instance of AbstractApp class!'); } $instance->setName($name); $this->instances[$name] = $instance; } return $this->instances[$name]; }
/** * Inits all loaded apps, calls core specific actions and maps */ private function initApps() { // Run app specfic functions /* @var $app \Core\Amvc\App\Abstractapp */ foreach ($this->apps as $app) { // Call additional Init() methods in apps if (method_exists($app, 'Init')) { $app->Init(); } switch ($app->getName()) { case 'Core': $config = $this->config->getStorage('Core'); // Create home url $type = $this->user->isGuest() ? 'guest' : 'user'; $route = $config->get('home.' . $type . '.route'); $params = parse_ini_string($config->get('home.' . $type . '.params')); $config->set('url.home', $app->url($route, $params)); break; } } }