public function actionInit($args) { $app = \Gini\Core::moduleInfo(APP_ID); $composer_json = ['name' => $app->id, 'description' => $app->description ?: '', 'license' => 'proprietary', 'repositories' => [['type' => 'composer', 'url' => 'http://satis.genee.cn']]]; $opt = \Gini\Util::getOpt($args, 'n', ['no-packagist']); if (isset($opt['n']) || isset($opt['--no-packagist'])) { $composer_json['repositories'][] = ['packagist' => false]; echo "Generating Composer configuration file without Packagist...\n"; } else { echo "Generating Composer configuration file...\n"; } $walked = []; $walk = function ($info) use(&$walk, &$walked, &$composer_json) { $walked[$info->id] = true; foreach ($info->dependencies as $name => $version) { if (isset($walked[$name])) { continue; } $app = \Gini\Core::moduleInfo($name); if ($app) { $walk($app); } } $composer_json = \Gini\Util::arrayMergeDeep($info->composer ?: [], $composer_json); }; $walk($app); if (isset($composer_json['require']) || isset($composer_json['require-dev'])) { if (file_exists(APP_PATH . '/composer.json')) { $confirm = strtolower(readline('File exists. Overwrite? [Y/n] ')); if ($confirm && $confirm != 'y') { echo " [33mcanceled.[0m\n"; return; } } file_put_contents(APP_PATH . '/composer.json', J($composer_json, JSON_PRETTY_PRINT)); echo " [32mdone.[0m\n"; } }
private static function _load_config_dir($base, &$items) { if (!is_dir($base)) { return; } $dh = opendir($base); if ($dh) { while ($name = readdir($dh)) { if ($name[0] == '.') { continue; } $file = $base . '/' . $name; if (!is_file($file)) { continue; } $category = pathinfo($name, PATHINFO_FILENAME); if (!isset($items[$category])) { $items[$category] = []; } switch (pathinfo($name, PATHINFO_EXTENSION)) { case 'php': $config =& $items[$category]; call_user_func(function () use(&$config, $file) { include $file; }); break; case 'yml': case 'yaml': $content = file_get_contents($file); $content = preg_replace_callback('/\\{\\{([A-Z0-9_]+?)\\}\\}/', function ($matches) { return getenv($matches[1]) ?: $matches[0]; }, $content); $content = preg_replace_callback('/\\$\\{([A-Z0-9_]+?)\\}/', function ($matches) { return getenv($matches[1]) ?: $matches[0]; }, $content); $content = trim($content); if ($content) { $config = (array) yaml_parse($content); $items[$category] = \Gini\Util::arrayMergeDeep($items[$category], $config); } break; } } closedir($dh); } }