Beispiel #1
0
 public function actionRun($name = null)
 {
     $job = \Gini\Config::get('cron')[$name];
     if (!$job) {
         return false;
     }
     $command_args = \Gini\Util::parseArgs($job['command']);
     ob_start();
     \Gini\CLI::dispatch($command_args);
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }
Beispiel #2
0
 public function actionExport($args)
 {
     $opt = \Gini\Util::getOpt($args, 'h', ['help', 'json', 'yaml']);
     if (isset($opt['h']) || isset($opt['help'])) {
         echo "Usage: gini config export [-h|--help] [--json|--yaml]\n";
         return;
     }
     \Gini\Config::setup();
     $items = \Gini\Config::export();
     if (isset($opt['json'])) {
         echo J($items, JSON_PRETTY_PRINT) . "\n";
     } else {
         echo yaml_emit($items, YAML_UTF8_ENCODING);
     }
 }
Beispiel #3
0
 public function actionExport($args)
 {
     $gini_bin = $_SERVER['_'];
     $opt = \Gini\Util::getOpt($args, 'hu:', ['help', 'user:'******'prefix:', 'suffix:']);
     if (isset($opt['h']) || isset($opt['help'])) {
         echo "Usage: gini cron export [-h|--help] [-u|--user=USER] [--prefix=PREFIX] [--suffix=SUFFIX]\n";
         return;
     }
     $prefix = $opt['prefix'] ?: '';
     $suffix = $opt['suffix'] ?: '';
     $user = $opt['u'] ?: $opt['user'] ?: '';
     foreach ((array) \Gini\Config::get('cron') as $cron) {
         if ($cron['comment']) {
             printf("# %s\n", $cron['comment']);
         }
         printf("%s%s\t%s%s @%s %s%s\n\n", $cron['interval'], $user ? "\t{$user}" : '', $prefix, $gini_bin, APP_ID, $cron['command'], $suffix);
     }
 }
Beispiel #4
0
 public function actionCache($args)
 {
     $opt = \Gini\Util::getOpt($args, 'he:', ['help', 'env:']);
     if (isset($opt['h']) || isset($opt['help'])) {
         echo "Usage: gini cache [-h|--help] [-e|--env=ENV] [clean]\n";
         return;
     }
     $env = $opt['e'] ?: $opt['env'] ?: null;
     if ($opt['_'][0] == 'clean') {
         \Gini\App\Cache::clean();
     } else {
         $errors = \Gini\App\Doctor::diagnose(['dependencies', 'composer']);
         if ($errors) {
             return;
         }
         \Gini\App\Cache::setup($env);
     }
 }
Beispiel #5
0
 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 "   canceled.\n";
                 return;
             }
         }
         file_put_contents(APP_PATH . '/composer.json', J($composer_json, JSON_PRETTY_PRINT));
         echo "   done.\n";
     }
 }
Beispiel #6
0
 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);
     }
 }
Beispiel #7
0
 public function actionUpdate($args)
 {
     if (APP_ID == 'gini') {
         echo "Please run it in your App directory!\n";
         return;
     }
     $opt = \Gini\Util::getOpt($args, 'f', ['force']);
     $force = isset($opt['f']) || isset($opt['force']);
     $web_dir = APP_PATH . '/web';
     \Gini\File::ensureDir($web_dir);
     $cgi_path = realpath(dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . '/../lib/cgi.php');
     $index_path = $web_dir . '/index.php';
     if (file_exists($index_path) || is_link($index_path)) {
         unlink($index_path);
     }
     file_put_contents($index_path, "<?php require \"{$cgi_path}\";\n");
     $this->_merge_assets($force);
     $this->_process_css($force);
     $this->_process_js($force);
 }
Beispiel #8
0
 public function testGetOpt()
 {
     $opt = \Gini\Util::getOpt(['bar', '--prefix=hello', 'foo', '--suffix'], '', ['prefix:', 'suffix:']);
     $this->assertEquals($opt['prefix'], 'hello');
     $this->assertFalse($opt['suffix']);
 }