Example #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];
 }