本文整理汇总了PHP中Cli类的典型用法代码示例。如果您正苦于以下问题:PHP Cli类的具体用法?PHP Cli怎么用?PHP Cli使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cli类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: render_cli_error
private function render_cli_error($heading, array $messages, $traces = [])
{
$cli = new Cli();
$cli->error(sprintf('<underline><bold>%s</bold></underline>', $heading));
foreach ($messages as $label => $message) {
$cli->error(sprintf('%s : <bold>%s</bold>', $label, $message));
}
if ($traces) {
$cli->br()->error('<underline><bold>Backtrace</bold></underline>');
$i = 1;
foreach ($traces as $error) {
$line = isset($error['line']) ? $error['line'] : 'Unknown';
if (isset($error['file'])) {
$console->out(' ' . $i . ') ' . str_replace(FCPATH, './', $error['file']) . ':' . $line);
} else {
$i--;
}
$func = '';
if (isset($error['class'], $error['type'])) {
$func .= $error['class'] . $error['type'];
}
$func .= $error['function'];
$console->error(' ' . $func . '()');
$i++;
}
}
}
开发者ID:projek-xyz,项目名称:ci-console,代码行数:27,代码来源:ExceptionsTrait.php
示例2: shoulLoadCliCommand
/** @test */
public function shoulLoadCliCommand()
{
$kernel = $this->mockFactory->getKernelMock(array('log'));
$cli = new Cli($kernel);
$kernel->expects($this->at(2))->method('log')->with($this->stringContains('Done'));
$cli->handle(array('c' => 'widget.WithCli.simple'));
}
开发者ID:hoborglabs,项目名称:dashboard,代码行数:8,代码来源:CliTest.php
示例3: main
/**
* Main method.
*/
public static function main()
{
list($command, $arguments, $config) = self::preProcess();
$migration = new Migration($config);
try {
$cli = new Cli();
$cli->execute($migration, $command, $arguments, $config);
} catch (\Exception $e) {
$debug = $migration->getConfig()->get('debug');
$colors = $migration->getConfig()->get('colors');
if (isset($debug) && $debug) {
if ($colors) {
fputs(STDERR, pack('c', 0x1b) . "[1;37;41m" . $e . pack('c', 0x1b) . "[0m\n");
} else {
fputs(STDERR, $e);
}
} else {
if ($colors) {
fputs(STDERR, pack('c', 0x1b) . "[1;37;41m" . $e->getMessage() . pack('c', 0x1b) . "[0m\n");
} else {
fputs(STDERR, $e->getMessage() . "\n");
}
}
}
}
开发者ID:kohkimakimoto,项目名称:lib-migration,代码行数:28,代码来源:Cli.php
示例4: testRun
/**
* @return void
* @covers \pFlow\Cli<extended>
* @group pflow
* @group unittest
*/
public function testRun()
{
$_SERVER['argv'] = array('pflow', '--recursive', 'some_path');
$analyzerMock = $this->getMock('\\pFlow\\AnalyzerInterface');
$analyzerMock->expects($this->once())->method('setSources')->with($this->equalTo(array('some_path')), $this->isTrue());
$cli = new Cli($analyzerMock, new \ezcConsoleInput());
$cli->run();
}
开发者ID:naderman,项目名称:pflow,代码行数:14,代码来源:CliTest.php
示例5: testException
/**
* @expectedException RuntimeException
*/
public function testException()
{
$cli = new Cli();
$cli->setTempDir(sys_get_temp_dir());
$cli->setLogger($this->getMockBuilder('Monolog\\Logger')->disableOriginalConstructor()->getMock());
$code = Code::fromString('throw new \\Exception("test");');
$result = $cli->run($code);
}
开发者ID:gordalina,项目名称:cachetool,代码行数:11,代码来源:CliTest.php
示例6: show_php_error
public static function show_php_error(\Exception $e)
{
$data['type'] = get_class($e);
$data['severity'] = $e->getCode();
$data['message'] = $e->getMessage();
$data['filepath'] = $e->getFile();
$data['error_line'] = $e->getLine();
$data['backtrace'] = $e->getTrace();
$data['severity'] = !isset(static::$levels[$data['severity']]) ? $data['severity'] : static::$levels[$data['severity']];
if (\Fuel::$is_cli) {
\Cli::write(\Cli::color($data['severity'] . ' - ' . $data['message'] . ' in ' . \Fuel::clean_path($data['filepath']) . ' on line ' . $data['error_line'], 'red'));
return;
}
$debug_lines = array();
foreach ($data['backtrace'] as $key => $trace) {
if (!isset($trace['file'])) {
unset($data['backtrace'][$key]);
} elseif ($trace['file'] == COREPATH . 'classes/error.php') {
unset($data['backtrace'][$key]);
}
}
$debug_lines = array('file' => $data['filepath'], 'line' => $data['error_line']);
$data['severity'] = !isset(static::$levels[$data['severity']]) ? $data['severity'] : static::$levels[$data['severity']];
$data['debug_lines'] = \Debug::file_lines($debug_lines['file'], $debug_lines['line']);
$data['filepath'] = \Fuel::clean_path($debug_lines['file']);
$data['filepath'] = str_replace("\\", "/", $data['filepath']);
$data['error_line'] = $debug_lines['line'];
echo \View::factory('errors' . DS . 'php_error', $data);
}
开发者ID:netspencer,项目名称:fuel,代码行数:29,代码来源:error.php
示例7: init
public static function init($args)
{
try {
if (!isset($args[1])) {
static::help();
return;
}
switch ($args[1]) {
case 'g':
case 'generate':
switch ($args[2]) {
case 'controller':
case 'model':
case 'view':
case 'views':
case 'migration':
call_user_func('Oil\\Generate::' . $args[2], array_slice($args, 3));
break;
case 'scaffold':
call_user_func('Oil\\Scaffold::generate', array_slice($args, 3));
break;
default:
Generate::help();
}
break;
case 'c':
case 'console':
new Console();
case 'r':
case 'refine':
$task = isset($args[2]) ? $args[2] : null;
call_user_func('Oil\\Refine::run', $task, array_slice($args, 3));
break;
case 'p':
case 'package':
switch ($args[2]) {
case 'install':
case 'uninstall':
call_user_func_array('Oil\\Package::' . $args[2], array_slice($args, 3));
break;
default:
Package::help();
}
break;
case '-v':
case '--version':
\Cli::write('Fuel: ' . \Fuel::VERSION);
break;
case 'test':
\Fuel::add_package('octane');
call_user_func('\\Fuel\\Octane\\Tests::run_' . $args[2], array_slice($args, 3));
break;
default:
static::help();
}
} catch (Exception $e) {
\Cli::write(\Cli::color('Error: ' . $e->getMessage(), 'light_red'));
\Cli::beep();
}
}
开发者ID:netspencer,项目名称:fuel,代码行数:60,代码来源:cli.php
示例8: __construct
/**
* ChallengeAbstract constructor.
*/
public function __construct()
{
if (!Cli::isCli()) {
throw new \DomainException('This challenge is supposed to be run from cli');
}
$this->solve();
}
开发者ID:Umkus,项目名称:codeeval,代码行数:10,代码来源:ChallengeAbstract.php
示例9: run
/**
* Run the credential importer
*
* @param string $json_file The JSON file that contains a list of the APIs and their credentials
*/
public static function run($json_file = null)
{
if (empty($json_file) || file_exists($json_file) === false) {
exit('You must specify a valid JSON file that contains your credentials.' . PHP_EOL);
}
if (($json = json_decode(file_get_contents($json_file), true)) === null) {
exit('The JSON file does not contain valid JSON text.' . PHP_EOL);
}
// Find the API version to use for importing the keys
$version = 'V1';
if (!empty($json[0]['version'])) {
if (is_int($json[0]['version']) && \Module::exists('V' . $json[0]['version'])) {
\Module::load('V' . $json[0]['version']);
$version = 'V' . $json[0]['version'];
} else {
\Module::load($version);
}
array_shift($json);
} else {
\Module::load($version);
}
$error = false;
foreach ($json as $entry) {
// We need these keys for each entry.
if (!array_key_exists('api', $entry) || !array_key_exists('credentials', $entry)) {
echo \Cli::color('The JSON data is in the wrong format. Skipping.' . PHP_EOL, 'yellow');
$error = true;
continue;
}
if (!is_string($entry['api'])) {
echo \Cli::color('The API name must be a string. Skipping.' . PHP_EOL, 'yellow');
$error = true;
continue;
}
// Make sure that we have credentials to add to the DB.
if (empty($entry['credentials']) || !is_array($entry['credentials'])) {
echo \Cli::color('The array of credentials for ' . $entry['api'] . ' is empty. Skipping.' . PHP_EOL, 'yellow');
$error = true;
continue;
}
$response = call_user_func('\\' . $version . '\\Keyring::set_credentials', $entry['credentials'], $entry['api']);
// Show and log the result
if ($response === true) {
$success_text = 'Successfully imported the credentials for API: ' . $entry['api'];
echo \Cli::color($success_text . PHP_EOL, 'green');
\Log::logger('INFO', 'CLI:ADD_CREDENTIALS', $success_text, __METHOD__, array('api' => $entry['api']));
} else {
$error_text = 'Failed to import the credentials for API: ' . $entry['api'];
echo \Cli::color('Warning: ' . $error_text . PHP_EOL, 'red');
$error = true;
\Log::logger('ERROR', 'CLI:ADD_CREDENTIALS', $error_text, __METHOD__, array('api' => $entry['api']));
}
}
// Display the summary.
if ($error === true) {
echo \Cli::color(PHP_EOL . 'Some credentials were not added to the database. See the error log for more details.' . PHP_EOL, 'red');
} else {
echo \Cli::color(PHP_EOL . 'All credentials were successfully added to the database.' . PHP_EOL, 'green');
}
}
开发者ID:bitapihub,项目名称:api-optimization-engine,代码行数:65,代码来源:apicredentials.php
示例10: receive_sqs_for_multi
public static function receive_sqs_for_multi()
{
$t1 = microtime(true);
$pcount = 3;
$pstack = array();
for ($i = 1; $i <= $pcount; $i++) {
$pid = pcntl_fork();
if ($pid == -1) {
die('fork できません');
} else {
if ($pid) {
// 親プロセスの場合
$pstack[$pid] = true;
if (count($pstack) >= $pcount) {
unset($pstack[pcntl_waitpid(-1, $status, WUNTRACED)]);
}
} else {
sleep(1);
self::receive_sqs_message();
exit;
//処理が終わったらexitする。
}
}
}
//先に処理が進んでしまうので待つ
while (count($pstack) > 0) {
unset($pstack[pcntl_waitpid(-1, $status, WUNTRACED)]);
}
$t2 = microtime(true);
$process_time = $t2 - $t1;
\Cli::write("Process time = " . $process_time);
}
开发者ID:inoue2302,项目名称:phplib,代码行数:32,代码来源:sqs.php
示例11: monitor
public function monitor($file, $channel)
{
if (false === ($fp = @fopen($file, "r"))) {
Cli::error("Failed to open {$file}");
} else {
Cli::out("Monitoring file: {$file}");
}
while (1) {
if (-1 === fseek($fp, 0, SEEK_END) or !($pos = ftell($fp))) {
goto retry;
}
if ($this->lastPosition === null or $this->lastPosition > $pos) {
$this->lastPosition = $pos;
goto retry;
}
if ($this->lastPosition < $pos) {
fseek($fp, $this->lastPosition - $pos, SEEK_CUR);
if (false === ($content = fread($fp, $pos - $this->lastPosition))) {
goto retry;
}
try {
$this->client->send($content, $channel);
} catch (\Exception $ex) {
Cli::error($ex->getMessage());
}
$this->lastPosition = $pos;
}
retry:
usleep(200000);
}
}
开发者ID:joy2fun,项目名称:websocket-console-client,代码行数:31,代码来源:FileClient.php
示例12: 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);
}
}
开发者ID:netspencer,项目名称:fuel,代码行数:26,代码来源:refine.php
示例13: exitWithFailedRequest
/**
* @param string $msg A message to display before exiting
*
* @author Panagiotis Vagenas <[email protected]>
* @since 0-dev
*/
public static function exitWithFailedRequest($msg = '')
{
if ($msg) {
Cli::writeError($msg);
}
self::exitWith(self::EXIT_CODE_VALID_REQUEST_FAILED);
}
开发者ID:wordfence,项目名称:exkit,代码行数:13,代码来源:ExitCodes.php
示例14: test_spawn_speed
public function test_spawn_speed()
{
$start = time();
\Cli::spawn('sleep 2');
$stop = time();
$this->assertEquals($start, $stop);
}
开发者ID:469306621,项目名称:Languages,代码行数:7,代码来源:cli.php
示例15: 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;
}
开发者ID:phabos,项目名称:fuel-core,代码行数:66,代码来源:input.php
示例16: bootstrap
public function bootstrap()
{
$this->constant();
//加载服务配置项
$servers = (require __DIR__ . '/service.php');
$config = (require ROOT_PATH . '/system/config/service.php');
$servers['providers'] = array_merge($config['providers'], $servers['providers']);
$servers['facades'] = array_merge($config['facades'], $servers['facades']);
$this->servers = $servers;
//自动加载系统服务
Loader::register([$this, 'autoload']);
//绑定核心服务提供者
$this->bindServiceProvider();
//添加初始实例
$this->instance('App', $this);
//设置外观类APP属性
ServiceFacade::setFacadeApplication($this);
//启动服务
$this->boot();
//定义错误/异常处理
Error::bootstrap();
//命令行模式
IS_CLI and die(Cli::bootstrap());
//导入类库别名
Loader::addMap(c('app.alias'));
//自动加载文件
Loader::autoloadFile();
//开启会话
Session::start();
//执行全局中间件
Middleware::globals();
//解析路由
Route::dispatch();
}
开发者ID:houdunwang,项目名称:hdphp,代码行数:34,代码来源:App.php
示例17: 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);
}
}
开发者ID:nasumi,项目名称:fuel,代码行数:30,代码来源:refine.php
示例18: execute
public final function execute()
{
$hasThreads = function_exists('pcntl_signal');
if (!$hasThreads || Cli::getInstance()->isSimulation()) {
flush();
try {
return $this->executeNoThread();
} catch (Interrupt $e) {
throw $e;
} catch (Exception $e) {
echo $e;
}
return;
}
pcntl_signal(SIGCHLD, SIG_IGN);
$pid = pcntl_fork();
if ($pid < 1) {
$this->_run();
posix_kill(posix_getpid(), 9);
pcntl_waitpid(posix_getpid(), $temp = 0, WNOHANG);
pcntl_wifexited($temp);
exit;
//Make sure we exit...
} else {
$this->pid = $pid;
}
}
开发者ID:hofmeister,项目名称:Pimple,代码行数:27,代码来源:Thread.php
示例19: 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;
}
开发者ID:469306621,项目名称:Languages,代码行数:60,代码来源:uri.php
示例20: getInstance
public static function getInstance($argv = null)
{
if (self::$instance === null) {
self::$instance = new Cli($argv);
}
return self::$instance;
}
开发者ID:GrapheneProject,项目名称:Graphene,代码行数:7,代码来源:cli.php
注:本文中的Cli类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论