本文整理汇总了PHP中Zend_Console_Getopt::getRemainingArgs方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Console_Getopt::getRemainingArgs方法的具体用法?PHP Zend_Console_Getopt::getRemainingArgs怎么用?PHP Zend_Console_Getopt::getRemainingArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Console_Getopt
的用法示例。
在下文中一共展示了Zend_Console_Getopt::getRemainingArgs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Main Entry Point
* */
public function run()
{
//deal with command line argument
try {
$opts = new Zend_Console_Getopt(array('discover|d' => 'special Twitter search for PHP around Ottawa (not saved)'));
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
// if special argument is received
if (isset($opts->d)) {
$this->fetchTwitterSpecial($opts->getRemainingArgs());
} else {
$this->fetchBlogs();
$this->fetchTwitter();
// clear all cache
$cacheConfig = $this->application->getBootstrap()->getOption('cache');
if ($cacheConfig['enabled']) {
$cache = Zend_Cache::factory('Page', 'File', array(), $cacheConfig['backend']);
echo PHP_EOL . '->clearing cache' . PHP_EOL;
$cache->clean(Zend_Cache::CLEANING_MODE_ALL);
}
}
}
示例2: routeStartup
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
try {
$opts = new Zend_Console_Getopt(array('controller|c=s' => 'Name of the controller to open', 'action|a=s' => 'The command line action to execute', 'cityId|ci=i' => 'City id to get trend data for', 'startDate|sd=s' => 'Start date for the price trends', 'endDate|ed=s' => 'End date for the price trends', 'hours|h=i' => 'How many hours to simulate for'));
$opts->parse();
$args = $opts->getRemainingArgs();
if (!isset($opts->action)) {
throw new Zend_Console_Getopt_Exception('Action parameter missing');
}
$cliAction = $opts->action;
$cliController = $opts->controller;
$paramters = array();
$optArray = $opts->toArray();
for ($i = 0; $i < count($optArray); $i += 2) {
$paramters[$optArray[$i]] = $optArray[$i + 1];
}
} catch (Zend_Console_Getopt_Exception $e) {
echo $opts->getUsageMessage();
exit;
}
// set the request as a CLI request
$request = new Zend_Controller_Request_Simple($cliAction, $cliController, 'cli');
foreach ($paramters as $key => $paramVal) {
$request->setParam($key, $paramVal);
}
foreach ($args as $argument) {
$request->setParam($argument, true);
}
$response = new Zend_Controller_Response_Cli();
$front = Zend_Controller_Front::getInstance();
$front->setRequest($request)->setResponse($response);
}
示例3: route
/**
*
* @param Zend_Controller_Request_Abstract $dispatcher
* @return Zend_Controller_Request_Abstract
*/
public function route(Zend_Controller_Request_Abstract $dispatcher)
{
$getopt = new Zend_Console_Getopt(array());
$arguments = $getopt->getRemainingArgs();
$controller = null;
$action = null;
$params = array();
if ($arguments) {
foreach ($arguments as $index => $command) {
if (preg_match('/([a-z0-9]+)=([a-z0-9]+)/i', trim($command), $match)) {
switch ($match[1]) {
case 'controller':
$controller = $match[2];
break;
case 'action':
$action = $match[2];
break;
default:
$params[$match[1]] = $match[2];
}
}
}
$action = empty($action) ? 'index' : $action;
$controller = empty($controller) ? 'index' : $controller;
$dispatcher->setControllerName($controller);
$dispatcher->setActionName($action);
$dispatcher->setParams($params);
return $dispatcher;
}
echo "Invalid command.\n";
echo "No command given.\n", exit;
}
示例4: importEmployee
/**
* import employee data from csv file
*
* @param Zend_Console_Getopt $opts
* @return integer
*/
public function importEmployee($opts)
{
$args = $opts->getRemainingArgs();
array_push($args, 'definition=' . 'hr_employee_import_csv');
if ($opts->d) {
array_push($args, '--dry');
}
if ($opts->v) {
array_push($args, '--verbose');
}
$opts->setArguments($args);
$result = $this->_import($opts);
if (empty($result)) {
return 2;
}
foreach ($result as $filename => $importResult) {
$importedEmployee = $this->_getImportedEmployees($importResult);
foreach ($importedEmployee as $employee) {
$this->_sanitizeEmployee($opts, $employee);
$currentEmployee = $this->_getCurrentEmployee($employee);
if ($currentEmployee) {
$employee = $this->_updateImportedEmployee($opts, $employee, $currentEmployee);
} else {
$employee = $this->_createImportedEmployee($opts, $employee);
}
if ($opts->v) {
print_r($employee->toArray());
}
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($employee->toArray(), TRUE));
}
}
}
return 0;
}
示例5: route
public function route(Zend_Controller_Request_Abstract $dispatcher)
{
$getopt = new Zend_Console_Getopt(array());
$arguments = $getopt->getRemainingArgs();
$controller = "";
$action = "";
$params = array();
if ($arguments) {
foreach ($arguments as $index => $command) {
$details = explode("=", $command);
if ($details[0] == "controller") {
$controller = $details[1];
} else {
if ($details[0] == "action") {
$action = $details[1];
} else {
$params[$details[0]] = $details[1];
}
}
}
if ($action == "" || $controller == "") {
die("\n\t\t\t\t\t\tMissing Controller and Action Arguments\n\t\t\t\t\t\t==\n\t\t\t\t\t\tYou should have:\n\t\t\t\t\t\tphp script.php controller=[controllername] action=[action] token=[token]\n\t\t\t\t\t\t");
}
$dispatcher->setModuleName('cronjob');
$dispatcher->setControllerName($controller);
$dispatcher->setActionName($action);
$dispatcher->setParams($params);
return $dispatcher;
}
echo "Invalid command.\n", exit;
echo "No command given.\n", exit;
}
示例6: route
public function route(Zend_Controller_Request_Abstract $dispatcher)
{
$getopt = new Zend_Console_Getopt(array());
$arguments = $getopt->getRemainingArgs();
$controller = 'index';
$action = 'index';
if ($arguments) {
$controller = array_shift($arguments);
if ($arguments) {
$action = array_shift($arguments);
$pattern_valid_action = '~^\\w+[\\-\\w\\d]+$~';
if (false == preg_match($pattern_valid_action, $action)) {
echo "Invalid action {$action}.\n", exit;
}
if ($arguments) {
foreach ($arguments as $arg) {
$parameter = explode('=', $arg, 2);
if (false == isset($parameter[1])) {
$parameter[1] = true;
}
$dispatcher->setParam($parameter[0], $parameter[1]);
unset($parameter);
}
}
}
}
$dispatcher->setControllerName($controller)->setActionName($action);
return $dispatcher;
}
示例7: route
public function route(Zend_Controller_Request_Abstract $dispatcher)
{
try {
$getopt = new Zend_Console_Getopt(array('verbose|v' => 'Print verbose output', 'file|f=s' => 'File to upload'));
$getopt->parse;
$arguments = $getopt->getRemainingArgs();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
if ($arguments) {
$command = array_shift($arguments);
$action = array_shift($arguments);
if (!preg_match('~\\W~', $command)) {
$dispatcher->setControllerName($command);
$dispatcher->setActionName($action);
$dispatcher->setParams($arguments);
if (isset($getopt->v)) {
$dispatcher->setParam('verbose', true);
}
if (isset($getopt->f)) {
$dispatcher->setParam('file', $getopt->f);
}
return $dispatcher;
}
echo "Invalid command.\n", exit;
}
echo "No command given.\n", exit;
}
示例8: importegw14
/**
* import from egroupware
*
* @param Zend_Console_Getopt $_opts
*/
public function importegw14($_opts)
{
//$args = $_opts->getRemainingArgs();
list($host, $username, $password, $dbname, $charset) = $_opts->getRemainingArgs();
$egwDb = Zend_Db::factory('PDO_MYSQL', array('host' => $host, 'username' => $username, 'password' => $password, 'dbname' => $dbname));
$egwDb->query("SET NAMES {$charset}");
$writer = new Zend_Log_Writer_Stream('php://output');
$logger = new Zend_Log($writer);
$config = new Zend_Config(array('egwServerTimezone' => 'UTC', 'setPersonalCalendarGrants' => TRUE, 'forcePersonalCalendarGrants' => FALSE));
$importer = new Calendar_Setup_Import_Egw14($egwDb, $config, $logger);
$importer->import();
}
示例9: route
public function route(Zend_Controller_Request_Abstract $dispatcher)
{
$getopt = new Zend_Console_Getopt(array());
$getopt->addRules(array('controller|c=s' => 'Controller Name', 'action|a=s' => 'Controller Action', 'from|f=s' => 'From yyyy-mm-dd', 'to|t=s' => 'To yyyy-mm-dd'));
$arguments = $getopt->getRemainingArgs();
if ($getopt->getOption('controller') && $getopt->getOption('action')) {
$dispatcher->setControllerName($getopt->getOption('controller'));
$dispatcher->setActionName($getopt->getOption('action'));
$dispatcher->setParams(array('from' => $getopt->getOption('from'), 'to' => $getopt->getOption('to')));
return $dispatcher;
}
}
示例10: parse
public function parse()
{
// get actionname from arguments
if (count($this->_arguments) == 0) {
return;
}
// action name will be a free floating string
$actionName = array_shift($this->_arguments);
// check to make sure that the action exists
if (!($actionContext = $this->_buildManifest->getContext('action', $actionName)) instanceof Zend_Build_Manifest_Context) {
require_once 'Zend/Tool/Cli/Context/Exception.php';
throw new Zend_Tool_Cli_Context_Exception('No action context by name ' . $actionName . ' was found in the manifest.');
}
$getoptRules = array();
// get the attributes from this action context
$actionContextAttrs = $actionContext->getAttributes();
foreach ($actionContextAttrs as $actionContextAttr) {
if (isset($actionContextAttr['attributes']['getopt'])) {
$getoptRules[$actionContextAttr['attributes']['getopt']] = $actionContextAttr['usage'];
}
}
// parse those options out of the arguments array
$getopt = new Zend_Console_Getopt($getoptRules, $this->_arguments, array('parseAll' => false));
$getopt->parse();
// put remaining args into local property
$this->_arguments = $getopt->getRemainingArgs();
// get class name
$actionClassName = $actionContext->getClassName();
// load appropriate file
try {
Zend_Loader::loadClass($actionClassName);
} catch (Zend_Loader_Exception $e) {
echo 'couldnt load ' . $actionClassName . PHP_EOL;
}
// get actual object for class name
$this->_action = new $actionClassName();
// make sure its somewhat sane (implements proper interface)
if (!$this->_action instanceof Zend_Build_Action_Abstract) {
echo 'does not implement Zend_Build_Action_Abstract ' . PHP_EOL;
}
$parameters = array();
foreach ($getopt->getOptions() as $getoptParsedOption) {
$parameters[$getoptParsedOption] = $getopt->getOption($getoptParsedOption);
}
$this->_action->setParameters($parameters);
$this->_action->validate();
$this->setExecutable();
return;
// everything succeeded
}
示例11: exportICS
/**
* exports calendars as ICS
*
* @param Zend_Console_Getopt $_opts
*/
public function exportICS($_opts)
{
Tinebase_Core::set('HOSTNAME', 'localhost');
$opts = $_opts->getRemainingArgs();
$container_id = $opts[0];
$filter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $container_id)));
$result = Calendar_Controller_MSEventFacade::getInstance()->search($filter, null, false, false, 'get');
if ($result->count() == 0) {
throw new Tinebase_Exception('this calendar does not contain any records.');
}
$converter = Calendar_Convert_Event_VCalendar_Factory::factory("generic");
$result = $converter->fromTine20RecordSet($result);
print $result->serialize();
}
示例12: parseCommandLine
public function parseCommandLine()
{
try {
$opts = new Zend_Console_Getopt(array('development|d' => 'development mode', 'verbose|v' => 'verbose output', 'json|j' => 'JSON output'));
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
if ($opts->getOption('d')) {
$this->_environment = 'development';
}
$args = $opts->getRemainingArgs();
if (count($args) < 1) {
$args = array('help');
}
$this->_controller = array_shift($args);
if (count($args) < 1) {
$args = array('help');
}
$this->_action = array_shift($args);
$this->_arguments = $args;
return $this;
}
示例13: testRemainingArgs
public function testRemainingArgs()
{
$opts = new Zend_Console_Getopt('abp:', array('-a', '--', 'file1', 'file2'));
$this->assertEquals(implode(',', $opts->getRemainingArgs()), 'file1,file2');
$opts = new Zend_Console_Getopt('abp:', array('-a', 'file1', 'file2'));
$this->assertEquals(implode(',', $opts->getRemainingArgs()), 'file1,file2');
}
示例14: parse
public function parse()
{
$endpointRequest = $this->_endpoint->getRequest();
if ($this->_workingArguments[0] == $_SERVER["SCRIPT_NAME"]) {
array_shift($this->_workingArguments);
}
if (!$this->_parseGlobalPart() || count($this->_workingArguments) == 0) {
// @todo process global options?
return;
}
$actionName = array_shift($this->_workingArguments);
// is the action name valid?
$cliActionNameMetadatas = Zend_Tool_Rpc_Manifest_Registry::getInstance()->getMetadatas(array('type' => 'Action', 'name' => 'cliActionName'));
foreach ($cliActionNameMetadatas as $cliActionNameMetadata) {
if ($actionName == $cliActionNameMetadata->getValue()) {
$action = $cliActionNameMetadata->getReference();
break;
}
}
$endpointRequest->setActionName($action->getName());
/* @TODO Action Parameter Requirements */
if (count($this->_workingArguments) == 0) {
return;
}
if (!$this->_parseActionPart() || count($this->_workingArguments) == 0) {
return;
}
$cliProviderName = array_shift($this->_workingArguments);
$cliSpecialtyName = '_global';
if (strstr($cliProviderName, '.')) {
list($cliProviderName, $cliSpecialtyName) = explode('.', $cliProviderName);
}
$cliProviderNameMetadatas = Zend_Tool_Rpc_Manifest_Registry::getInstance()->getMetadatas(array('type' => 'Provider', 'name' => 'cliProviderName'));
foreach ($cliProviderNameMetadatas as $cliProviderNameMetadata) {
if ($cliProviderName == $cliProviderNameMetadata->getValue()) {
$provider = $cliProviderNameMetadata->getReference();
break;
}
}
$endpointRequest->setProviderName($provider->getName());
$cliSpecialtyNameMetadatas = Zend_Tool_Rpc_Manifest_Registry::getInstance()->getMetadatas(array('type' => 'Provider', 'providerName' => $provider->getName(), 'name' => 'cliSpecialtyNames'));
foreach ($cliSpecialtyNameMetadatas as $cliSpecialtyNameMetadata) {
if ($cliSpecialtyName == $cliSpecialtyNameMetadata->getValue()) {
$specialtyName = $cliSpecialtyNameMetadata->getSpecialtyName();
break;
}
}
$endpointRequest->setSpecialtyName($specialtyName);
$cliActionableMethodLongParameterMetadata = Zend_Tool_Rpc_Manifest_Registry::getInstance()->getMetadata(array('type' => 'Provider', 'providerName' => $provider->getName(), 'actionName' => $action->getName(), 'specialtyName' => $specialtyName, 'name' => 'cliActionableMethodLongParameters'));
$cliActionableMethodShortParameterMetadata = Zend_Tool_Rpc_Manifest_Registry::getInstance()->getMetadata(array('type' => 'Provider', 'providerName' => $provider->getName(), 'actionName' => $action->getName(), 'specialtyName' => $specialtyName, 'name' => 'cliActionableMethodShortParameters'));
$cliParameterNameShortValues = $cliActionableMethodShortParameterMetadata->getValue();
$getoptOptions = array();
foreach ($cliActionableMethodLongParameterMetadata->getValue() as $parameterNameLong => $cliParameterNameLong) {
$optionConfig = $cliParameterNameLong . '|';
$cliActionableMethodReferenceData = $cliActionableMethodLongParameterMetadata->getReference();
if ($cliActionableMethodReferenceData['type'] == 'string' || $cliActionableMethodReferenceData['type'] == 'bool') {
$optionConfig .= $cliParameterNameShortValues[$parameterNameLong] . ($cliActionableMethodReferenceData['optional'] ? '-' : '=') . 's';
} elseif (in_array($cliActionableMethodReferenceData['type'], array('int', 'integer', 'float'))) {
$optionConfig .= $cliParameterNameShortValues[$parameterNameLong] . ($cliActionableMethodReferenceData['optional'] ? '-' : '=') . 'i';
} else {
$optionConfig .= $cliParameterNameShortValues[$parameterNameLong] . '-s';
}
$getoptOptions[$optionConfig] = $cliActionableMethodReferenceData['description'] != '' ? $cliActionableMethodReferenceData['description'] : 'No description available.';
}
$getoptParser = new Zend_Console_Getopt($getoptOptions, $this->_workingArguments, array('parseAll' => false));
$getoptParser->parse();
foreach ($getoptParser->getOptions() as $option) {
$value = $getoptParser->getOption($option);
$endpointRequest->setProviderParameter($option, $value);
}
/*
Zend_Debug::dump($getoptParser);
Zend_Debug::dump($endpointRequest);
die();
*/
$this->_workingArguments = $getoptParser->getRemainingArgs();
return;
}
示例15: testUsingDashWithoutOptionNameAsLastArgumentIsRecognizedAsRemainingArgument
/**
* @group ZF-5345
*/
public function testUsingDashWithoutOptionNameAsLastArgumentIsRecognizedAsRemainingArgument()
{
$opts = new Zend_Console_Getopt("abp:", array("-"));
$opts->parse();
$this->assertEquals(1, count($opts->getRemainingArgs()));
$this->assertEquals(array("-"), $opts->getRemainingArgs());
}