public function actionScan($argv) { if (count($argv) < 1) { exit("usage: [1;34mgini i18n scan[0m [<locales>]\n"); } $info = \Gini\Core::moduleInfo(APP_ID); if (!isset($info->id)) { echo "[1;34mgini i18n scan[0m: Invalid app path!\n"; exit; } $path = $info->path; $domain = str_replace('/', '-', $info->id); $l10n_path = $path . '/' . RAW_DIR . '/l10n'; \Gini\File::ensureDir($l10n_path); $l10n_template = $l10n_path . '/template.pot'; if (file_exists($l10n_template)) { unlink($l10n_template); } $keywords = '--keyword=T'; //$package = sprintf('--package-name=%s --package-version=%s', $cmd = sprintf('cd %s && find class view -name "*.php" -o -name "*.phtml" | xargs xgettext -LPHP %s --from-code=UTF-8 -i --copyright-holder=%s --foreign-user --package-name=%s --package-version=%s --msgid-bugs-address=%s -o %s', escapeshellarg($path), $keywords, escapeshellarg($info->author ?: 'Gini Team'), escapeshellarg($info->id), escapeshellarg($info->version), escapeshellarg($info->email ?: '*****@*****.**'), escapeshellarg($l10n_template)); passthru($cmd); // extract msgid ""{context}\004{txt} to msgctxt and msgid $cmd = sprintf("sed 's/msgid \"\\(.*\\)''/msgctxt \"\\1\"\\nmsgid \"/g' %s", escapeshellarg($l10n_template)); // echo $cmd . "\n"; die; file_put_contents($l10n_template, `{$cmd}`); $locales = $argv; foreach (glob($l10n_path . '/*.po') as $fname) { $locale = basename($fname, '.po'); $locales[] = $locale; } foreach (array_unique($locales) as $locale) { $locale_arr = \Locale::parseLocale($locale); if (!isset($locale_arr['language'])) { continue; } $l10n_pofile = $l10n_path . '/' . $locale . '.po'; if (!file_exists($l10n_pofile)) { $cmd = sprintf('msginit --no-translator -o %1$s -i %2$s -l %3$s', escapeshellarg($l10n_pofile), escapeshellarg($l10n_template), escapeshellarg($locale)); } else { $cmd = sprintf('msgmerge --update --suffix=none --no-fuzzy-matching -q %1$s %2$s', escapeshellarg($l10n_pofile), escapeshellarg($l10n_template)); } passthru($cmd); } echo "done.\n"; //merge po file to different locale directory }
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"; } }
public static function commandVersion() { $info = \Gini\Core::moduleInfo('gini'); echo "{$info->name} ({$info->id}/{$info->version})\n"; }
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); } } }
public static function setup() { $host = $_SERVER['HTTP_HOST']; $scheme = $_SERVER['HTTP_X_FORWARDED_PROTO'] ?: ($_SERVER['HTTPS'] ? 'https' : 'http'); $dir = dirname($_SERVER['SCRIPT_NAME']); if (substr($dir, -1) != '/') { $dir .= '/'; } self::$_base = $scheme . '://' . $host . $dir; self::$_rurl = \Gini\Core::moduleInfo(APP_ID)->rurl ?: ['*' => 'assets']; }
public function actionVersion($argv) { $info = \Gini\Core::moduleInfo(APP_ID); $version = $argv[0]; if ($version) { // set current version $v = new \Gini\Version($version); $v->compare($info->version) > 0 or die("A newer version (>{$info->version}) is required!\n"); $info->version = $version; \Gini\Core::saveModuleInfo($info); // commit it if it is a git repo if (is_dir(APP_PATH . '/.git')) { $WORK_TREE = escapeshellarg(APP_PATH); $GIT_DIR = escapeshellarg(APP_PATH . '/.git'); $GIT_MSG = escapeshellarg("Bumped version to {$version}"); $command = "git --git-dir={$GIT_DIR} --work-tree={$WORK_TREE} commit -m {$GIT_MSG} gini.json && git --git-dir={$GIT_DIR} tag {$version}"; passthru($command); return; } } echo "{$info->name} ({$info->id}/{$info->version})\n"; }
private static function _rurl_mod($url, $type) { $info = \Gini\Core::moduleInfo(APP_ID); $config = (array) \Gini\Config::get('system.rurl_mod'); if ($type) { $query = $config[$type]['query']; $query = $query ? strtr($query, ['$(TIMESTAMP)' => time(), '$(VERSION)' => $info->version]) : null; } return empty($query) ? $url : self::url($url, $query); }