本文整理汇总了PHP中Cli::option方法的典型用法代码示例。如果您正苦于以下问题:PHP Cli::option方法的具体用法?PHP Cli::option怎么用?PHP Cli::option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cli
的用法示例。
在下文中一共展示了Cli::option方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install
public static function install($package = null)
{
// Make sure something is set
if ($package === null) {
static::help();
return;
}
$version = \Cli::option('version', 'master');
// Check to see if this package is already installed
if (is_dir(PKGPATH . $package)) {
throw new \FuelException('Package "' . $package . '" is already installed.');
return;
}
$request_url = static::$_api_url . 'cells/show.json?name=' . urlencode($package);
$response = json_decode(@file_get_contents($request_url), true);
if (!$response) {
throw new \FuelException('No response from the API. Perhaps check your internet connection?');
}
if (empty($response['cell'])) {
throw new \FuelException('Could not find the cell "' . $package . '".');
}
$cell = $response['cell'];
// Now, lets get this package
// If it is git and (they have git installed (TODO) and they havent asked for a zip)
if ($cell['repository_type'] == 'git' and !\Cli::option('via-zip')) {
\Cli::write('Downloading package: ' . $package);
static::_clone_package_repo($cell['repository_url'], $package, $version);
} else {
\Cli::write('Downloading package: ' . $package);
static::_download_package_zip($zip_url, $package, $version);
}
}
示例2: uri
/**
* Detects and returns the current URI based on a number of different server
* variables.
*
* @return string
*/
public static function uri()
{
if (static::$detected_uri !== null) {
return static::$detected_uri;
}
if (\Fuel::$is_cli) {
if ($uri = \Cli::option('uri') !== null) {
static::$detected_uri = $uri;
} else {
static::$detected_uri = \Cli::option(1);
}
return static::$detected_uri;
}
// We want to use PATH_INFO if we can.
if (!empty($_SERVER['PATH_INFO'])) {
$uri = $_SERVER['PATH_INFO'];
} elseif (!empty($_SERVER['ORIG_PATH_INFO']) and ($path = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['ORIG_PATH_INFO'])) != '') {
$uri = $path;
} else {
// Fall back to parsing the REQUEST URI
if (isset($_SERVER['REQUEST_URI'])) {
$uri = $_SERVER['REQUEST_URI'];
} else {
throw new \FuelException('Unable to detect the URI.');
}
// Remove the base URL from the URI
$base_url = parse_url(\Config::get('base_url'), PHP_URL_PATH);
if ($uri != '' and strncmp($uri, $base_url, strlen($base_url)) === 0) {
$uri = substr($uri, strlen($base_url));
}
// If we are using an index file (not mod_rewrite) then remove it
$index_file = \Config::get('index_file');
if ($index_file and strncmp($uri, $index_file, strlen($index_file)) === 0) {
$uri = substr($uri, strlen($index_file));
}
// When index.php? is used and the config is set wrong, lets just
// be nice and help them out.
if ($index_file and strncmp($uri, '?/', 2) === 0) {
$uri = substr($uri, 1);
}
// Lets split the URI up in case it contains a ?. This would
// indicate the server requires 'index.php?' and that mod_rewrite
// is not being used.
preg_match('#(.*?)\\?(.*)#i', $uri, $matches);
// If there are matches then lets set set everything correctly
if (!empty($matches)) {
$uri = $matches[1];
$_SERVER['QUERY_STRING'] = $matches[2];
parse_str($matches[2], $_GET);
}
}
// Strip the defined url suffix from the uri if needed
if (strpos($uri, '.') !== false) {
static::$detected_ext = preg_replace('#(.*)\\.#', '', $uri);
$uri = substr($uri, 0, -(strlen(static::$detected_ext) + 1));
}
// Do some final clean up of the uri
static::$detected_uri = \Security::clean_uri($uri, true);
return static::$detected_uri;
}
示例3: run
public static function run($task, $args)
{
// Just call and run() or did they have a specific method in mind?
list($task, $method)=array_pad(explode(':', $task), 2, 'run');
$task = ucfirst(strtolower($task));
if ( ! $file = \Fuel::find_file('tasks', $task))
{
throw new \Exception('Well that didnt work...');
return;
}
require $file;
$task = '\\Fuel\\Tasks\\'.$task;
$new_task = new $task;
// The help option hs been called, so call help instead
if (\Cli::option('help') && is_callable(array($new_task, 'help')))
{
$method = 'help';
}
if ($return = call_user_func_array(array($new_task, $method), $args))
{
\Cli::write($return);
}
}
示例4: install
public static function install($package = null)
{
// Make sure something is set
if ($package === null) {
static::help();
return;
}
$config = \Config::load('package');
$version = \Cli::option('version', 'master');
// Check to see if this package is already installed
if (is_dir(PKGPATH . $package)) {
throw new Exception('Package "' . $package . '" is already installed.');
return;
}
foreach ($config['sources'] as $source) {
$packages = array('fuel-' . $package, $package);
foreach ($packages as $package) {
$zip_url = 'http://' . rtrim($source, '/') . '/' . $package . '/zipball/' . $version;
if ($fp = @fopen($zip_url, 'r')) {
// We don't actually need this, just checking the file is there
fclose($fp);
// Now, lets get this package
// If a direct download is requested, or git is unavailable, download it!
if (\Cli::option('direct') or static::_use_git() === false) {
static::_download_package_zip($zip_url, $package, $version);
exit;
} else {
static::_clone_package_repo($source, $package, $version);
exit;
}
}
}
}
throw new Exception('Could not find package "' . $package . '".');
}
示例5: run
public static function run()
{
\Config::load('migrations', true);
$current_version = \Config::get('migrations.version');
// -v or --version
$version = \Cli::option('v', \Cli::option('version'));
// version is used as a flag, so show it
if ($version === true) {
\Cli::write('Currently on migration: ' . $current_version . '.', 'green');
return;
} else {
if (!is_null($version) and $version == $current_version) {
throw new \Oil\Exception('Migration: ' . $version . ' already in use.');
return;
}
}
$run = false;
// Specific version
if (is_numeric($version) and $version >= 0) {
if (\Migrate::version($version) === false) {
throw new \Oil\Exception('Migration ' . $version . ' could not be found.');
} else {
static::_update_version($version);
\Cli::write('Migrated to version: ' . $version . '.', 'green');
}
} else {
if (($result = \Migrate::latest()) === false) {
throw new \Oil\Exception("Could not migrate to latest version, still using {$current_version}.");
} else {
static::_update_version($result);
\Cli::write('Migrated to latest version: ' . $result . '.', 'green');
}
}
}
示例6: run
/**
* Show help.
*
* Usage (from command line):
*
* php oil refine simple2orm
*/
public static function run()
{
// fetch the commandline options
$run_migration = \Cli::option('migrate', \Cli::option('m', false));
$run_validation = $run_migration ? true : \Cli::option('validate', \Cli::option('v', false));
// if no run options are present, show the help
if (!$run_migration and !$run_validation) {
return static::help();
}
// step 1: run validation
$validated = true;
if ($run_validation) {
$validated = static::run_validation();
}
// step 2: run migration
if ($run_migration) {
if ($validated) {
$migrated = static::run_migration();
if ($migrated) {
\Cli::write('Migration succesfully finished', 'light_green');
} else {
\Cli::write("\n" . 'Migration failed. Skipping the remainder of the migration. Please correct the errors and run again.', 'light_red');
}
} else {
\Cli::write("\n" . 'Validation failed. Skipping the actual migration. Please correct the errors.', 'light_red');
}
}
}
示例7: detect
public static function detect()
{
if (static::$detected_uri !== null) {
return static::$detected_uri;
}
if (\Fuel::$is_cli) {
if ($uri = \Cli::option('uri') !== null) {
static::$detected_uri = $uri;
} else {
static::$detected_uri = \Cli::option(1);
}
return static::$detected_uri;
}
// We want to use PATH_INFO if we can.
if (!empty($_SERVER['PATH_INFO'])) {
$uri = $_SERVER['PATH_INFO'];
} elseif (!empty($_SERVER['ORIG_PATH_INFO']) and ($path = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['ORIG_PATH_INFO'])) != '') {
$uri = $path;
} else {
// Fall back to parsing the REQUEST URI
if (isset($_SERVER['REQUEST_URI'])) {
// Some servers require 'index.php?' as the index page
// if we are using mod_rewrite or the server does not require
// the question mark, then parse the url.
if (\Config::get('index_file') != 'index.php?') {
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
} else {
$uri = $_SERVER['REQUEST_URI'];
}
} else {
throw new \Fuel_Exception('Unable to detect the URI.');
}
// Remove the base URL from the URI
$base_url = parse_url(\Config::get('base_url'), PHP_URL_PATH);
if ($uri != '' and strncmp($uri, $base_url, strlen($base_url)) === 0) {
$uri = substr($uri, strlen($base_url));
}
// If we are using an index file (not mod_rewrite) then remove it
$index_file = \Config::get('index_file');
if ($index_file and strncmp($uri, $index_file, strlen($index_file)) === 0) {
$uri = substr($uri, strlen($index_file));
}
// Lets split the URI up in case it containes a ?. This would
// indecate the server requires 'index.php?' and that mod_rewrite
// is not being used.
preg_match('#(.*?)\\?(.*)#i', $uri, $matches);
// If there are matches then lets set set everything correctly
if (!empty($matches)) {
$uri = $matches[1];
$_SERVER['QUERY_STRING'] = $matches[2];
parse_str($matches[2], $_GET);
}
}
// Strip the defined url suffix from the uri if needed
$ext = \Config::get('url_suffix');
strrchr($uri, '.') === $ext and $uri = substr($uri, 0, -strlen($ext));
// Do some final clean up of the uri
static::$detected_uri = str_replace(array('//', '../'), '/', $uri);
return static::$detected_uri;
}
示例8: run
public static function run($task, $args)
{
// Make sure something is set
if ($task === null or $task === 'help') {
static::help();
return;
}
// Just call and run() or did they have a specific method in mind?
list($task, $method) = array_pad(explode(':', $task), 2, 'run');
$task = ucfirst(strtolower($task));
// Find the task
if (!($file = \Fuel::find_file('tasks', $task))) {
throw new Exception(sprintf('Task "%s" does not exist.', $task));
return;
}
require $file;
$task = '\\Fuel\\Tasks\\' . $task;
$new_task = new $task();
// The help option hs been called, so call help instead
if (\Cli::option('help') && is_callable(array($new_task, 'help'))) {
$method = 'help';
}
if ($return = call_user_func_array(array($new_task, $method), $args)) {
\Cli::write($return);
}
}
示例9: run
/**
* Listen to a queue
*
* @param mixed $queue
*/
public function run($queue = 'default', $connector = null)
{
$worker = \Worker::forge($queue, $connector);
// Register shutdown function to catch exit
// \Event::register('shutdown', $this->shutdown);
$interval = \Cli::option('interval', \Cli::option('i', 5));
$worker->listen($interval);
}
示例10: run
public static function run($task, $args = array())
{
$task = strtolower($task);
// Make sure something is set
if (empty($task) or $task === 'help') {
static::help();
return;
}
$module = false;
list($module, $task) = array_pad(explode('::', $task), 2, null);
if ($task === null) {
$task = $module;
$module = false;
}
if ($module) {
try {
\Module::load($module);
$path = \Module::exists($module);
\Finder::instance()->add_path($path);
} catch (\FuelException $e) {
throw new Exception(sprintf('Module "%s" does not exist.', $module));
}
}
// Just call and run() or did they have a specific method in mind?
list($task, $method) = array_pad(explode(':', $task), 2, 'run');
// Find the task
if (!($file = \Finder::search('tasks', $task))) {
$files = \Finder::instance()->list_files('tasks');
$possibilities = array();
foreach ($files as $file) {
$possible_task = pathinfo($file, \PATHINFO_FILENAME);
$difference = levenshtein($possible_task, $task);
$possibilities[$difference] = $possible_task;
}
ksort($possibilities);
if ($possibilities and current($possibilities) <= 5) {
throw new Exception(sprintf('Task "%s" does not exist. Did you mean "%s"?', $task, current($possibilities)));
} else {
throw new Exception(sprintf('Task "%s" does not exist.', $task));
}
return;
}
require_once $file;
$task = '\\Fuel\\Tasks\\' . ucfirst($task);
$new_task = new $task();
// The help option has been called, so call help instead
if ((\Cli::option('help') or $method == 'help') and is_callable(array($new_task, 'help'))) {
$method = 'help';
} else {
// if the task has an init method, call it now
is_callable($task . '::_init') and $task::_init();
}
if ($return = call_fuel_func_array(array($new_task, $method), $args)) {
\Cli::write($return);
}
}
示例11: original_uri
public static function original_uri()
{
if (static::$uri !== null) {
return static::$uri;
}
if (\Fuel::$is_cli) {
if ($uri = \Cli::option('uri') !== null) {
static::$uri = $uri;
} else {
static::$uri = \Cli::option(1);
}
return static::$uri;
}
// We want to use PATH_INFO if we can.
if (!empty($_SERVER['PATH_INFO'])) {
$uri = $_SERVER['PATH_INFO'];
} elseif (!empty($_SERVER['ORIG_PATH_INFO']) and ($path = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['ORIG_PATH_INFO'])) != '') {
$uri = $path;
} else {
// Fall back to parsing the REQUEST URI
if (isset($_SERVER['REQUEST_URI'])) {
$uri = urldecode($_SERVER['REQUEST_URI']);
} else {
throw new \FuelException('CMF was unable to detect the URI.');
}
// Remove the base URL from the URI
$base_url = parse_url(\Config::get('base_url'), PHP_URL_PATH);
if ($uri != '' and strncmp($uri, $base_url, strlen($base_url)) === 0) {
$uri = substr($uri, strlen($base_url));
}
// If we are using an index file (not mod_rewrite) then remove it
$index_file = \Config::get('index_file');
if ($index_file and strncmp($uri, $index_file, strlen($index_file)) === 0) {
$uri = substr($uri, strlen($index_file));
}
// When index.php? is used and the config is set wrong, lets just
// be nice and help them out.
if ($index_file and strncmp($uri, '?/', 2) === 0) {
$uri = substr($uri, 1);
}
// Lets split the URI up in case it contains a ?. This would
// indicate the server requires 'index.php?' and that mod_rewrite
// is not being used.
preg_match('#(.*?)\\?(.*)#i', $uri, $matches);
// If there are matches then lets set set everything correctly
if (!empty($matches)) {
$uri = $matches[1];
$_SERVER['QUERY_STRING'] = $matches[2];
parse_str($matches[2], $_GET);
}
}
// Deal with any trailing dots
$uri = '/' . trim(rtrim($uri, '.'), '/');
return static::$uri = $uri;
}
示例12: forge
/**
* Forge
*
* @param array Fields mainly
* @param string Subfolder (or admin "theme") where views are held
* @return mixed
*/
public static function forge($args, $subfolder)
{
$data = array();
$subfolder = trim($subfolder, '/');
if (!is_dir(PKGPATH . 'oil/views/' . static::$view_subdir . $subfolder)) {
throw new Exception('The subfolder for admin templates does not exist or is spelled wrong: ' . $subfolder . ' ');
}
// Go through all arguments after the first and make them into field arrays
$data['fields'] = array();
foreach (array_slice($args, 1) as $arg) {
// Parse the argument for each field in a pattern of name:type[constraint]
preg_match(static::$fields_regex, $arg, $matches);
$data['fields'][] = array('name' => \Str::lower($matches[1]), 'type' => isset($matches[2]) ? $matches[2] : 'string', 'constraint' => isset($matches[4]) ? $matches[4] : null);
}
$name = array_shift($args);
// Replace / with _ and classify the rest. DO NOT singularize
$controller_name = \Inflector::classify(static::$controller_prefix . str_replace(DS, '_', $name), false);
// Replace / with _ and classify the rest. Singularize
$model_name = \Inflector::classify(static::$model_prefix . str_replace(DS, '_', $name));
// Either foo or folder/foo
$view_path = $controller_path = str_replace(array('_', '-'), DS, \Str::lower($controller_name));
// Models are always singular, tough!
$model_path = str_replace(array('_', '-'), DS, \Str::lower($model_name));
// uri's have forward slashes, DS is a backslash on Windows
$uri = str_replace(DS, '/', $controller_path);
$data['include_timestamps'] = !\Cli::option('no-timestamp', false);
// If a folder is used, the entity is the last part
$name_parts = explode(DS, $name);
$data['singular_name'] = \Inflector::singularize(end($name_parts));
$data['plural_name'] = \Inflector::pluralize($data['singular_name']);
$data['table'] = \Inflector::tableize($model_name);
$data['controller_parent'] = static::$controller_parent;
/** Generate the Migration **/
$migration_args = $args;
array_unshift($migration_args, 'create_' . \Inflector::pluralize(\Str::lower($name)));
Generate::migration($migration_args, false);
// Merge some other data in
$data = array_merge(compact(array('controller_name', 'model_name', 'model_path', 'view_path', 'uri')), $data);
/** Generate the Model **/
$model = \View::forge(static::$view_subdir . $subfolder . '/model', $data);
Generate::create(APPPATH . 'classes/model/' . $model_path . '.php', $model, 'model');
/** Generate the Controller **/
$controller = \View::forge(static::$view_subdir . $subfolder . '/controller', $data);
$controller->actions = array(array('name' => 'index', 'params' => '', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/index', $data)), array('name' => 'view', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/view', $data)), array('name' => 'create', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/create', $data)), array('name' => 'edit', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/edit', $data)), array('name' => 'delete', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/delete', $data)));
Generate::create(APPPATH . 'classes/controller/' . $controller_path . '.php', $controller, 'controller');
// Create each of the views
foreach (array('index', 'view', 'create', 'edit', '_form') as $view) {
Generate::create(APPPATH . 'views/' . $controller_path . '/' . $view . '.php', \View::forge(static::$view_subdir . $subfolder . '/views/actions/' . $view, $data), 'view');
}
// Add the default template if it doesnt exist
if (!file_exists($app_template = APPPATH . 'views/template.php')) {
Generate::create($app_template, file_get_contents(PKGPATH . 'oil/views/' . static::$view_subdir . $subfolder . '/views/template.php'), 'view');
}
Generate::build();
}
示例13: run
public static function run()
{
$version = \Cli::option('v', \Cli::option('version'));
if ($version > 0)
{
\Migrate::version($version);
}
else
{
\Migrate::current();
}
}
示例14: run
/**
* Send command with runtime option:
* php oil refine autho --install
* php oil refine autho --help
* php oil refine autho --test
*
* @static
* @access public
* @return void
*/
public static function run()
{
$install = \Cli::option('i', \Cli::option('install'));
$help = \Cli::option('h', \Cli::option('help'));
$test = \Cli::option('t', \Cli::option('test'));
switch (true) {
case null !== $install:
static::install($install);
break;
case null !== $test:
static::test();
break;
case null !== $help:
default:
static::help();
break;
}
}
示例15: create
public static function create($subjects, $fields)
{
$field_str = '';
$defined_columns = array();
foreach ($fields as $field) {
$name = array_shift($field);
$field_opts = array();
foreach ($field as $option => $val) {
if ($val === true) {
$field_opts[] = "'{$option}' => true";
} else {
if (is_int($val)) {
$field_opts[] = "'{$option}' => {$val}";
} else {
$field_opts[] = "'{$option}' => '{$val}'";
}
}
}
$field_opts = implode(', ', $field_opts);
$field_str .= "\t\t\t'{$name}' => array({$field_opts})," . PHP_EOL;
$defined_columns[$name] = true;
}
// ID Field
$field_str = "\t\t\t'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true)," . PHP_EOL . $field_str;
if (!\Cli::option('no-timestamps', false)) {
if (!isset($defined_columns['created_at'])) {
$field_str .= "\t\t\t'created_at' => array('constraint' => 11, 'type' => 'int')," . PHP_EOL;
}
if (!isset($definied_columns['updated_at'])) {
$field_str .= "\t\t\t'updated_at' => array('constraint' => 11, 'type' => 'int'),";
}
}
$up = <<<UP
\t\t\\DBUtil::create_table('{$subjects[1]}', array(
{$field_str}
\t\t), array('id'));
UP;
$down = <<<DOWN
\t\t\\DBUtil::drop_table('{$subjects[1]}');
DOWN;
return array($up, $down);
}