Esempio n. 1
0
 /**
  * @param string $name
  * @param waSystemConfig $config
  * @param bool $set_current
  * @throws waException
  * @return waSystem
  */
 public static function getInstance($name = null, waSystemConfig $config = null, $set_current = false)
 {
     if ($name === null) {
         if ($config && $config instanceof waAppConfig) {
             $name = $config->getName();
         } else {
             $name = self::$current;
         }
     }
     if (!isset(self::$instances[$name])) {
         if ($config === null && self::$current) {
             /**
              * @var $system waSystem
              */
             $system = self::$instances[self::$current];
             $locale = $set_current ? $system->getLocale() : null;
             $config = SystemConfig::getAppConfig($name, $system->getEnv(), $system->config->getRootPath(), $locale);
         }
         if ($config) {
             self::$instances[$name] = new self($config);
             if (!self::$instances[$name] instanceof waSystem) {
                 throw new waException(sprintf('Class "%s" is not of the type waSystem.', $config));
             }
         } else {
             throw new waException(sprintf('The "%s" system does not exist.', $name));
         }
     }
     if ($set_current) {
         self::setActive($name);
     } elseif (!self::$current || self::$current == 'wa-system') {
         self::$current = $name;
     }
     return self::$instances[$name];
 }