/** * @param string $name the name of the runtime folder, * @throws \Exception */ public static function createRuntimeFolders($name = 'runtime') { self::output("\n%gBuilding runtime '{$name}' folders.%n"); umask(0); $directories = Config::value('yiinitializr.app.directories.' . $name); if (null === $directories) { throw new \Exception("Unable to find 'yiinitializr.app.directories.{$name}' on the settings."); } if (!is_array($directories)) { $directories = array($directories); } foreach ($directories as $directory) { $runtime = $directory . '/' . $name; if (!file_exists($runtime)) { @mkdir($runtime, 02777); self::output("Your {$name} folder has been created on {$directory}."); } else { self::output("'{$name}' %pfolder already exists. No action has been executed.%n"); } } self::output("%gRuntime '{$name}' folders creation process finished.%n"); }
/** * Creates console application, if Yii is available */ private static function getYiiApplication() { if (!is_file(Config::value('yii.path') . '/yii.php')) { // nothing yet installed, return return null; } require_once Config::value('yii.path') . '/yii.php'; spl_autoload_register(array('YiiBase', 'autoload')); if (\Yii::app() === null) { if (!Config::value('envlock')) { $env = Console::prompt('Please, enter your environment -ie. "dev | prod | stage": ', array('default' => 'dev')); Initializer::buildEnvironmentFiles($env); } else { Console::output("\n%Benv.lock%n file found. No environment request required.\n"); Console::output("Note: if you wish to re-do enviroment setting merging, please remove the %Benv.lock%n file " . "from the Yiinitializr %Bconfig%n folder."); } Initializer::createRuntimeFolders(); Initializer::createRuntimeFolders('assets'); if (is_file(Config::value('yiinitializr.config.console'))) { $app = \Yii::createConsoleApplication(Config::value('yiinitializr.config.console')); } else { throw new \Exception("'yiinitializr.config.console' setting not found"); } } else { $app = \Yii::app(); } return $app; }
/** * Creates an application of the specified type using the default class or the custom one found in settings. * @param string $type the application type, can be 'web' or 'console' * @param mixed $config application configuration. This parameter will be passed as the parameter * to the constructor of the application class. * @return mixed the application instance */ protected static function createApplication($type, $config) { $class = Config::value('yiinitializr.app.' . $type . '.class'); if ($class !== null && file_exists($class)) { require_once $class; $class = pathinfo($class, PATHINFO_FILENAME); } else { $class = 'C' . ucfirst(strtolower($type)) . 'Application'; } $app = \Yii::createApplication($class, $config); return $app; }