Ejemplo n.º 1
0
 public function actionFormat($argv)
 {
     if (count($argv) < 1) {
         exit("usage: gini i18n format <locales>\n");
     }
     $appname = APP_ID;
     foreach ($argv as $locale) {
         $lodir = I18N_PATH . '/' . $locale . '/LC_MESSAGES';
         \Gini\File::ensureDir($lodir);
         $pofile = $lodir . '/' . $appname . '.po';
         $paths = \Gini\Core::filePaths(RAW_DIR . '/l10n/' . $locale . '.po');
         echo "merge: {$appname}.po\n";
         $cmd = sprintf('msgcat -o %1$s %2$s', escapeshellarg($pofile), implode(' ', array_map('escapeshellarg', $paths)));
         passthru($cmd);
         $mofile = $lodir . '/' . $appname . '.mo';
         echo "compile: {$appname}.po => {$appname}.mo\n";
         $cmd = sprintf('msgfmt -o %s %s', escapeshellarg($mofile), escapeshellarg($pofile));
         passthru($cmd);
     }
 }
Ejemplo n.º 2
0
 private static function _cacheConfig($env)
 {
     $plurals = self::_getORMPlurals();
     printf("%s\n", 'Updating config cache...');
     $config_items = \Gini\Config::fetch();
     // update orm plurals
     $c = (array) $config_items['orm']['plurals'];
     $c += array_filter($plurals, function ($v) use($c) {
         return in_array($v, $c);
     });
     $config_items['orm']['plurals'] = $c;
     $config_file = APP_PATH . '/cache/config.json';
     \Gini\File::ensureDir(APP_PATH . '/cache');
     file_put_contents($config_file, J($config_items));
     \Gini\Config::setup();
     echo "   done.\n";
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
 public function actionInstall($argv)
 {
     count($argv) > 0 || APP_ID != 'gini' or die("Usage: gini index install <module> <version>\n\n");
     if (!class_exists('\\Sabre\\DAV\\Client')) {
         self::_loadGiniComposer();
     }
     list($options, $headers) = self::_davOptionsAndHeaders();
     $client = new \Sabre\DAV\Client($options);
     $installedModules = [];
     $installModule = function ($module, $versionRange, $targetDir, $isApp = false) use(&$installModule, &$installedModules, &$client, &$options, &$headers) {
         if (isset($installedModules[$module])) {
             $info = $installedModules[$module];
             $v = new \Gini\Version($info->version);
             // if installed version is incorrect, abort the operation.
             if (!$v->satisfies($versionRange)) {
                 die("Conflict detected on {$module}! Installed: {$v->fullVersion} Expecting: {$versionRange}\n");
             }
         } else {
             // try to see if we've already got it somewhere
             if (isset(\Gini\Core::$MODULE_INFO[$module])) {
                 $info = \Gini\Core::$MODULE_INFO[$module];
                 $v = new \Gini\Version($info->version);
                 if ($v->satisfies($versionRange)) {
                     $matched = $v;
                 }
             }
             // fetch index.json
             echo "Fetching catalog of {$module}...\n";
             while (true) {
                 $response = $client->request('GET', $module . '/index.json', null, $headers);
                 if ($response['statusCode'] == 401 && isset($response['headers']['www-authenticate'])) {
                     // Authentication required
                     // prompt user/password and try again
                     if (!isset($options['userName'])) {
                         list($options, $headers) = self::_davOptionsAndHeaders(true);
                         $client = new \Sabre\DAV\Client($options);
                         continue;
                     }
                     $matched or die("Access denied for fetch catalog of {$module} .\n");
                     $response = null;
                 } elseif ($response['statusCode'] < 200 || $response['statusCode'] > 206) {
                     $matched or die('Error: ' . $response['statusCode'] . "\n");
                     $response = null;
                 }
                 break;
             }
             if ($response) {
                 $indexInfo = (array) json_decode($response['body'], true);
                 // find latest match version
                 foreach ($indexInfo as $version => $foo) {
                     $v = new \Gini\Version($version);
                     if ($v->satisfies($versionRange)) {
                         if ($matched) {
                             if ($matched->compare($v) > 0) {
                                 continue;
                             }
                         }
                         $matched = $v;
                     }
                 }
             }
             if (!$matched) {
                 die("Failed to locate required version!\n");
             }
             if (!$info || $matched->fullVersion != $info->version) {
                 $version = $matched->fullVersion;
                 $info = (object) $indexInfo[$version];
                 $tarPath = "{$module}/{$version}.tgz";
                 echo "Downloading {$module} from {$tarPath}...\n";
                 while (true) {
                     $response = $client->request('GET', $tarPath, null, $headers);
                     if ($response['statusCode'] == 401 && isset($response['headers']['www-authenticate'])) {
                         // Authentication required
                         // prompt user/password and try again
                         if (!isset($options['userName'])) {
                             list($options, $headers) = self::_davOptionsAndHeaders(true);
                             $client = new \Sabre\DAV\Client($options);
                             continue;
                         }
                         die("Access denied for fetch catalog of {$module}.\n");
                     }
                     if ($response['statusCode'] < 200 || $response['statusCode'] > 206) {
                         die('Error: ' . $response['statusCode'] . "\n");
                     }
                     break;
                 }
                 if ($isApp) {
                     $modulePath = $targetDir;
                 } else {
                     $modulePath = "{$targetDir}/modules/{$module}";
                 }
                 if (is_dir($modulePath) && file_exists($modulePath)) {
                     \Gini\File::removeDir($modulePath);
                 }
                 \Gini\File::ensureDir($modulePath);
                 echo "Extracting {$module}...\n";
                 $ph = popen('tar -zx -C ' . escapeshellcmd($modulePath), 'w');
                 if (is_resource($ph)) {
                     fwrite($ph, $response['body']);
                     pclose($ph);
                 }
             } else {
                 $version = $info->version;
                 echo "Found local copy of {$module}/{$version}.\n";
             }
             $installedModules[$module] = $info;
             echo "\n";
         }
         if ($info) {
             foreach ((array) $info->dependencies as $m => $r) {
                 if ($m == 'gini') {
                     continue;
                 }
                 $installModule($m, $r, $targetDir, false);
             }
         }
     };
     if (count($argv) > 0) {
         // e.g. gini install xxx
         $module = $argv[0];
         if (count($argv) > 1) {
             $versionRange = $argv[1];
         } else {
             $versionRange = readline('Please provide a version constraint for the ' . $module . ' requirement:');
         }
         $installModule($module, $versionRange, $_SERVER['PWD'] . "/{$module}", true);
     } else {
         // run: gini install, then you should be in module directory
         if (APP_ID != 'gini') {
             // try to install its dependencies
             $app = \Gini\Core::moduleInfo(APP_ID);
             $installedModules[APP_ID] = $app;
             $installModule(APP_ID, $app->version, APP_PATH, true);
         }
     }
 }
Ejemplo n.º 5
0
    public function actionCreate($args)
    {
        count($args) > 0 or die("Usage: gini ci phpunit create <Class\\For\\Test>\n");
        $class = $args[0];
        preg_match('|^[\\w\\\\]+$|', $class) or die("Usage: gini ci phpunit create <Class\\For\\Test>\n");
        echo "Creating {$class}\n";
        $pos = strrpos($class, '\\');
        if ($pos === false) {
            $namespace = '';
            $name = $class;
        } else {
            $namespace = '\\' . trim(substr($class, 0, $pos), '\\');
            $name = trim(substr($class, $pos + 1), '\\');
        }
        $content = <<<TEMPL
<?php

namespace Gini\\PHPUnit{$namespace};

require_once __DIR__ . '/../gini.php';

class {$name} extends \\Gini\\PHPUnit\\CLI {

    public function testHello() {
        \$this->assertTrue(false, "PLEASE IMPLEMENT THIS!");
    }

}

TEMPL;
        $dir = APP_PATH . '/tests/unit';
        if ($namespace) {
            $dir .= strtr($namespace, '\\', '/');
        }
        if (!file_exists($dir . '/' . $name . '.php')) {
            \Gini\File::ensureDir($dir);
            file_put_contents($dir . '/' . $name . '.php', $content);
            echo "   done.\n";
        } else {
            echo "   file exists!\n";
        }
    }