/** * @param Application $app */ public function register(Application $app) { $this->app = $app; $app['config'] = $this->readConfig(); $instance = null; $instanceOptions = implode('-', array_keys($app['config']['instance'])); switch ($instanceOptions) { case 'driver-file': case 'file-driver': $driver = null; switch ($app['config']['instance']['driver']) { case 'typo3': $driver = new Typo3Driver(); break; case 'symfony': $driver = new Symfony2Driver(); break; case 'magento': $driver = new MagentoDriver(); break; } $filename = $this->app["rootPath"] . DIRECTORY_SEPARATOR . ltrim($app['config']['instance']['file'], DIRECTORY_SEPARATOR); $instance = $driver->getInstanceName(array('configFilePath' => $filename)); break; case 'file': if (!class_exists('Symfony\\Component\\Yaml\\Yaml')) { throw new \RuntimeException('Unable to read yaml as the Symfony Yaml Component is not installed.'); } $filename = $this->app["rootPath"] . DIRECTORY_SEPARATOR . ltrim($app['config']['instance']['file'], DIRECTORY_SEPARATOR); $config = Yaml::parse($filename); if (isset($config['instance'])) { $instance = $config['instance']; } else { throw new \RuntimeException('Unable to read yaml as the Symfony Yaml Component is not installed.'); } break; case 'envvar': $instance = getenv($app['config']['instance']['envvar']); break; case 'driver': throw new \RuntimeException('You must set also "file" parameter with system configuration settings if you set "driver".'); default: $instance = null; } if (!isset($instance) || null == $instance) { throw new \RuntimeException('Unable to detect local instance name.'); } else { $app['instance'] = $instance; } }
/** * @param Application $app */ public function register(Application $app) { $app['config'] = $this->readConfig(); $instance = null; foreach ($app['config']['instance'] as $instanceSettingsType => $instanceSettingsValue) { switch ($instanceSettingsType) { case 'file': if (!class_exists('Symfony\\Component\\Yaml\\Yaml')) { throw new \RuntimeException('Unable to read yaml as the Symfony Yaml Component is not installed.'); } $filename = $this->rootPath . $instanceSettingsValue; $config = Yaml::parse($filename); if (isset($config['instance'])) { $instance = $config['instance']; } else { throw new \RuntimeException('Unable to read yaml as the Symfony Yaml Component is not installed.'); } break; case 'envvar': $instance = getenv($instanceSettingsValue); break; case 'driver': $driver = null; if (isset($instanceSettingsValue)) { switch ($instanceSettingsValue) { case 'typo3': $driver = new Typo3Driver(); break; case 'symfony': $driver = new Symfony2Driver(); break; case 'magento': $driver = new MagentoDriver(); break; } } else { throw new \RuntimeException('Driver is not test in instance / driver.'); } $instance = $driver->getInstanceName(); break; default: $instance = null; } } if (!isset($instance) || null == $instance) { throw new \RuntimeException('Unable to detect local instance name.'); } else { $app['instance'] = $instance; } }