当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Console_Getopt::parse方法代码示例

本文整理汇总了PHP中Zend_Console_Getopt::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Console_Getopt::parse方法的具体用法?PHP Zend_Console_Getopt::parse怎么用?PHP Zend_Console_Getopt::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Console_Getopt的用法示例。


在下文中一共展示了Zend_Console_Getopt::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setOptions

 /**
  * method to set the options from the command line
  * 
  * @return boolean true on success, else false
  */
 protected function setOptions()
 {
     try {
         $input = array('r|R|receive' => 'Receive files and process them into database', 'p|P|process' => 'Process files into database', 'c|C|calc|calculate' => 'Calculate lines in database', 'a|A|aggregate' => 'Aggregate lines for billrun', 'g|G|generate' => 'Generate xml and csv files of specific billrun', 'e|E|respond' => 'Respond to files that were processed', 'l|L|alert' => 'Process and detect alerts', 'h|H|help' => 'Displays usage information.', 'type-s' => 'Process: Ild type to use', 'stamp-s' => 'Process: Stamp to use for this run', 'path-s' => 'Process: Path of the process file', 'export-path-s' => 'Respond: The path To export files', 'workspace-s' => 'The path to the workspace directory', 'parser-s' => 'Process: Parser type (default fixed)', 'backup' => 'Process: Backup path after the file processed (default ./backup)', 'page-s' => 'the  page to aggregate', 'size-s' => 'the size of the page to aggregate', 'environment-s' => 'Environment of the running command', 'env-s' => 'Environment of the running command', 'fetchonly' => 'Only fetch data from remote or db instead of doing complete action');
         $this->options = new Zend_Console_Getopt($input);
         $this->options->parse();
     } catch (Zend_Console_Getopt_Exception $e) {
         $this->addOutput($e->getMessage() . "\n\n" . $e->getUsageMessage());
         return false;
     }
     return true;
 }
开发者ID:ngchie,项目名称:system,代码行数:17,代码来源:Cli.php

示例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);
 }
开发者ID:georgetutuianu,项目名称:licenta,代码行数:32,代码来源:CliInitializer.php

示例3: handle

 /**
  * handler for command line scripts
  * 
  * @return boolean
  */
 public function handle()
 {
     try {
         $opts = new Zend_Console_Getopt(array('help|h' => 'Display this help Message', 'verbose|v' => 'Output messages', 'config|c=s' => 'Path to config.inc.php file', 'setconfig' => 'Update config. To specify the key and value, append \' -- configKey="your_key" configValue="your config value"\'
                      Examples:
                        setup.php --setconfig -- configkey=sample1 configvalue=value11
                        setup.php --setconfig -- configkey=sample2 configvalue=arrayKey1:Value1,arrayKey2:value2', 'check_requirements' => 'Check if all requirements are met to install and run tine20', 'create_admin' => 'Create new admin user (or reactivate if already exists)', 'install-s' => 'Install applications [All] or comma separated list;' . ' To specify the login name and login password of the admin user that is created during installation, append \' -- adminLoginName="admin" adminPassword="password"\'' . ' To add imap or smtp settings, append (for example) \' -- imap="host:mail.example.org,port:143,dbmail_host:localhost" smtp="ssl:tls"\'', 'update-s' => 'Update applications [All] or comma separated list', 'uninstall-s' => 'Uninstall application [All] or comma separated list', 'list-s' => 'List installed applications', 'sync_accounts_from_ldap' => 'Import user and groups from ldap', 'egw14import' => 'Import user and groups from egw14
                      Examples: 
                       setup.php --egw14import egwdbhost egwdbuser egwdbpass egwdbname latin1
                       setup.php --egw14import egwdbhost egwdbuser egwdbpass egwdbname utf8'));
         $opts->parse();
     } catch (Zend_Console_Getopt_Exception $e) {
         echo "Invalid usage: {$e->getMessage()}\n\n";
         echo $e->getUsageMessage();
         exit;
     }
     if (count($opts->toArray()) === 0 || $opts->h || empty($opts->install) && empty($opts->update) && empty($opts->uninstall) && empty($opts->list) && empty($opts->sync_accounts_from_ldap) && empty($opts->egw14import) && empty($opts->check_requirements) && empty($opts->create_admin) && empty($opts->setconfig)) {
         echo $opts->getUsageMessage();
         exit;
     }
     if ($opts->config) {
         // add path to config.inc.php to include path
         $path = strstr($opts->config, 'config.inc.php') !== false ? dirname($opts->config) : $opts->config;
         set_include_path($path . PATH_SEPARATOR . get_include_path());
     }
     Setup_Core::initFramework();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Is cli request. method: ' . (isset($opts->mode) ? $opts->mode : 'EMPTY'));
     }
     $setupServer = new Setup_Frontend_Cli();
     #$setupServer->authenticate($opts->username, $opts->password);
     return $setupServer->handle($opts);
 }
开发者ID:rodrigofns,项目名称:ExpressoLivre3,代码行数:38,代码来源:Cli.php

示例4: 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);
         }
     }
 }
开发者ID:eleclerc,项目名称:ottawaphpcommunity,代码行数:28,代码来源:fetchContent.php

示例5: index

 public function index()
 {
     try {
         $opts = new Zend_Console_Getopt(array('help|h' => 'Displays usage information', 'profiling|p' => 'Turn on Magento\'s profiler', 'database|d' => 'Turn on profiling of db queries'));
         $opts->parse();
     } catch (Zend_Console_Getopt_Exception $e) {
         $this->out('I do apologise! ' . $e->getMessage(), "red");
         echo "\n" . str_replace("magentleman", "magentleman console", $e->getUsageMessage()) . "\n";
         exit;
     }
     // Help action
     if (isset($opts->help)) {
         $this->out("It's terribly simple to use me:", "green");
         echo "\n";
         echo str_replace("magentleman", "magentleman console", $opts->getUsageMessage());
         echo "\n";
         exit;
     }
     if (isset($opts->profiling)) {
         $this->profiling = true;
     }
     if (isset($opts->database)) {
         $this->database = true;
     }
     $this->clear();
     $this->out("");
     $this->out(" " . $this->greeting, "green");
     $this->out(" To get help using this console, visit our website at http://www.qipcreative.com/magentleman\n", "yellow");
     $this->startConsole();
 }
开发者ID:ngreimel,项目名称:magentleman,代码行数:30,代码来源:Console.php

示例6: init

 public function init()
 {
     // Define some CLI options
     $getopt = new Zend_Console_Getopt(array('withdata|w' => 'Load database with sample data', 'env|e-s' => 'Application environment for which to create database (defaults to development)', 'help|h' => 'Help -- usage message'));
     try {
         $getopt->parse();
     } catch (Zend_Console_Getopt_Exception $e) {
         // Bad options passed: report usage
         echo $e->getUsageMessage();
         return false;
     }
     // Initialize Zend_Application
     $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
     // Initialize and retrieve DB resource
     $bootstrap = $application->getBootstrap();
     $bootstrap->bootstrap('db');
     $dbAdapter = $bootstrap->getResource('db');
     // let the user know whats going on (we are actually creating a
     // database here)
     if ('testing' != APPLICATION_ENV) {
         echo 'Writing Database Guestbook in (control-c to cancel): ' . PHP_EOL;
         for ($x = 5; $x > 0; $x--) {
             echo $x . "\r";
             sleep(1);
         }
     }
     vd(1);
 }
开发者ID:kotmonstr,项目名称:zend,代码行数:28,代码来源:PatchController.php

示例7: parse

 /**
  * Parses the configuration options and populates the data store.
  *
  * @param bool $force if true; forces parsing independently of the _parsed property.
  *
  * @return void
  */
 public function parse($force = false)
 {
     if ($this->_parsed === true && !$force) {
         return $this;
     }
     $this->_parsed = false;
     try {
         parent::parse();
     } catch (Zend_Exception $e) {
         $name = basename($_SERVER['SCRIPT_NAME'], '.php');
         echo $name . ': ' . $e->getMessage() . PHP_EOL;
         echo 'Try: \'' . $name . ' --help\' for more information.' . PHP_EOL;
         exit(22);
     }
     if ($this->getHelp()) {
         DocBlox_Core_Application::renderVersion();
         echo $this->getUsageMessage();
         exit(0);
     }
     // prevent the loading of configuration files by specifying 'none'.
     if (strtolower($this->getConfig()) == 'none') {
         return;
     }
     if ($this->getConfig()) {
         // when the configuration parameter is provided; merge that with the basic config
         DocBlox_Core_Abstract::config()->merge(new Zend_Config_Xml($this->getConfig()));
     } elseif (is_readable('docblox.xml')) {
         // when the configuration is not provided; check for the presence of a configuration file in the current directory
         // and merge that
         DocBlox_Core_Abstract::config()->merge(new Zend_Config_Xml('docblox.xml'));
     } elseif (is_readable('docblox.dist.xml')) {
         // when no docblox.xml is provided; check for a dist.xml file. Yes, compared to, for example, PHPUnit the xml
         // and dist is reversed; this is done on purpose so IDEs have an easier time on it.
         DocBlox_Core_Abstract::config()->merge(new Zend_Config_Xml('docblox.dist.xml'));
     }
     $this->prePopulate();
     // the parse method does not have a hook point to invoke the setter methods; thus we iterate through the options and
     // invoke the setters. If no setter exists the __call method will handle this.
     // We have explicitly kept this intact (as the __call's set does nothing special) to enable subclasses to override
     // the __call and receive the benefits.
     foreach ($this->getOptions() as $value) {
         $method_name = '';
         // loop through all aliases to check whether a real method was overridden
         foreach ($this->_rules[$value]['alias'] as $alias) {
             $method_name = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $alias)));
             if (method_exists($this, $method_name)) {
                 // found one! execute it and continue to the next
                 $this->{$method_name}($this->getOption($value));
                 continue 2;
             }
         }
         if ($method_name == '') {
             throw new Exception('Unable to find a name for the setter for argument ' . $value);
         }
         // no overridden methods found; just invoke the default name to trigger the __call method
         $this->{$method_name}($this->getOption($value));
     }
 }
开发者ID:rvanvelzen,项目名称:phpDocumentor2,代码行数:65,代码来源:Abstract.php

示例8: _parseParams

 /**
  * Prepare options & aguments
  *
  * @return void
  */
 protected final function _parseParams()
 {
     $this->_parseArguments();
     $aOptions = $this->_parseOptions();
     try {
         $this->_oGetopt = new Zend_Console_Getopt($aOptions);
         $this->_oGetopt->parse();
     } catch (Zend_Console_Getopt_Exception $oException) {
         echo $oException->getUsageMessage();
         exit;
     }
 }
开发者ID:pansot2,项目名称:PadCMS-backend,代码行数:17,代码来源:Abstract.php

示例9: __construct

 public function __construct(Zend_Console_Getopt $getopt)
 {
     $this->_getopt = $getopt;
     $getopt->parse();
     if ($getopt->{$this->getModuleKey()}) {
         $this->setModuleName(HCLI_Controller_Util::decode($getopt->{$this->getModuleKey()}));
     }
     if ($getopt->{$this->getControllerKey()}) {
         $this->setControllerName(HCLI_Controller_Util::decode($getopt->{$this->getControllerKey()}));
     }
     if ($getopt->{$this->getActionKey()}) {
         $this->setActionName($getopt->{$this->getActionKey()});
     }
 }
开发者ID:bokultis,项目名称:kardiomedika,代码行数:14,代码来源:Cli.php

示例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
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:50,代码来源:Action.php

示例11: route

 /**
  * Processes a request and sets its controller and action.  If
  * no route was possible, an exception is thrown.
  *
  * @param  \Zend_Controller_Request_Abstract
  * @throws \Zend_Controller_Router_Exception
  * @return \Zend_Controller_Request_Abstract|boolean
  */
 public function route(\Zend_Controller_Request_Abstract $request)
 {
     $options = array('help|h' => 'Show this help', 'org|o=i' => 'The user organization number', 'pwd|p=s' => 'User password', 'user|u=s' => 'The user name');
     $getopt = new \Zend_Console_Getopt($options);
     try {
         $getopt->parse();
     } catch (\Zend_Console_Getopt_Exception $e) {
         echo $this->_expandMessage($e);
         exit;
     }
     if ($getopt->getOption('h')) {
         // $getopt->s
         echo $this->_expandMessage($getopt);
         exit;
     }
     if ($request instanceof \MUtil_Controller_Request_Cli) {
         $request->setUserLogin($getopt->getOption('u'), $getopt->getOption('o'), $getopt->getOption('p'));
     }
     $arguments = $getopt->getRemainingArgs();
     if ($arguments) {
         $controller = array_shift($arguments);
         $action = array_shift($arguments);
         if (!$action) {
             $action = 'index';
         }
         if (preg_match('/^\\w+(-\\w+)*$/', $controller) && preg_match('/^\\w+(-\\w+)*$/', $action)) {
             $request->setControllerName($controller);
             $request->setActionName($action);
             $params[$request->getControllerKey()] = $controller;
             $params[$request->getActionKey()] = $action;
             foreach ($arguments as $arg) {
                 if (\MUtil_String::contains($arg, '=')) {
                     list($name, $value) = explode('=', $arg, 2);
                 } else {
                     $name = $arg;
                     $value = '';
                 }
                 $params[$name] = $value;
             }
             $request->setParams($params);
             return $request;
         }
         echo "Invalid command: {$controller}/{$action}.\n", exit;
     }
     echo "No command given.\n\n";
     echo $this->_expandMessage($getopt), exit;
 }
开发者ID:GemsTracker,项目名称:MUtil,代码行数:55,代码来源:Cli.php

示例12: parse

 public function parse()
 {
     try {
         $getopt = new Zend_Console_Getopt($this->_globalGetoptRules(), $this->_arguments, array('parseAll' => false));
         $getopt->parse();
     } catch (Exception $e) {
         die($e->getMessage());
     }
     if (in_array('help', $getopt->getOptions())) {
         $this->setShortCircuited(true);
         $this->_displayHelp();
         return;
     }
     $this->setExecutable();
     // check if global switches are supported
     return;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:17,代码来源:Global.php

示例13: __construct

 public function __construct()
 {
     $flags = array('--' . $this->getActionKey(), '-a', '--' . $this->getControllerKey(), '-c', '--' . $this->getModuleKey(), '-m');
     $argv = array($_SERVER['argv'][0]);
     foreach ($_SERVER['argv'] as $key => $value) {
         if (in_array($value, $flags)) {
             $argv[] = $value;
             $argv[] = $_SERVER['argv'][$key + 1];
         }
     }
     require_once 'Zend/Console/Getopt.php';
     $getopt = new Zend_Console_Getopt($this->_getGetoptRules(), $argv);
     $getopt->parse();
     $this->setModuleName($getopt->getOption($this->getModuleKey()));
     $this->setControllerName($getopt->getOption($this->getControllerKey()));
     $this->setActionName($getopt->getOption($this->getActionKey()));
 }
开发者ID:sirprize,项目名称:xzend,代码行数:17,代码来源:Cli.php

示例14: main

function main()
{
    prepareEnvironment();
    try {
        $opts = new Zend_Console_Getopt(array('create application|a=s' => 'create application option with required string parameter', 'help' => 'help option with no required parameter'));
        $opts->parse();
    } catch (Zend_Console_Getopt_Exception $e) {
        echo $e->getUsageMessage();
        exit;
    }
    if ($applicationName = $opts->getOption('a')) {
        echo create(APPLICATION, array($applicationName));
        exit;
    }
    echo "UNEXPECTED ERROR: missing argument. Type tn -help to see parameters \n";
    exit;
}
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:17,代码来源:tn.php

示例15: __construct

 /**
  * Constructor 
  * @param Zend_Console_Getopt $getopt
  */
 public function __construct(Zend_Console_Getopt $getopt)
 {
     $this->_getopt = $getopt;
     try {
         $getopt->parse();
     } catch (Zend_Console_Getopt_Exception $e) {
         echo $e->getUsageMessage();
         exit(-1);
     }
     if ($getopt->{$this->getModuleKey()}) {
         $this->setModuleName($getopt->{$this->getModuleKey()});
     }
     if ($getopt->{$this->getControllerKey()}) {
         $this->setControllerName($getopt->{$this->getControllerKey()});
     }
     if ($getopt->{$this->getActionKey()}) {
         $this->setActionName($getopt->{$this->getActionKey()});
     }
 }
开发者ID:kandy,项目名称:system,代码行数:23,代码来源:Cli.php


注:本文中的Zend_Console_Getopt::parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。