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


PHP Zend_Console_Getopt类代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: configure

 private function configure()
 {
     $zend_console = new Zend_Console_Getopt(array('create|c' => 'Create database configureation', 'adapter|a=w' => 'Database adapter (mysql)', 'host|h=w' => 'Default to localhost', 'username|u=w' => 'Username to connect to database', 'password|p=w' => 'Password to connect to database', 'database|d=w' => 'Database Name', 'port|o-i' => '(optional) Port for connecting to database', 'socket|s-w' => '(optional) Location for database socket'), $this->argv);
     try {
         echo $a = $zend_console->getOption('a');
         echo $h = $zend_console->getOption('h');
         // Load all sections from an existing config file, while skipping the extends.
         $config = new Zend_Config_Ini(SMCONFIG_DIRECTORY . DIRECTORY_SEPARATOR . 'database.ini', null, array('skipExtends' => true, 'allowModifications' => true));
         // Modify values
         $config->database->doctrine_adapter = $zend_console->getOption('a');
         $config->database->params->host = $zend_console->getOption('h');
         $config->database->params->username = $zend_console->getOption('u');
         $config->database->params->password = $zend_console->getOption('p');
         $config->database->params->dbname = $zend_console->getOption('d');
         $config->database->params->port = $zend_console->getOption('h');
         $config->database->params->socket = $zend_console->getOption('h');
         // Write the config file
         $writer = new Zend_Config_Writer_Ini(array('config' => $config, 'filename' => 'config.ini'));
         $writer->write();
         //*/
     } catch (Zend_Console_Getopt_Exception $e) {
         fwrite(STDOUT, "Connection Failed\n");
         echo $e->getUsageMessage();
         exit;
     }
 }
开发者ID:jeremymoorecom,项目名称:Smallunch,代码行数:26,代码来源:database.class.php

示例5: 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

示例6: 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

示例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;
 }
开发者ID:RobertoMalatesta,项目名称:trade-capture,代码行数:29,代码来源:Cli.php

示例8: 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;
 }
开发者ID:fredcido,项目名称:simuweb,代码行数:37,代码来源:Cron.php

示例9: 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;
 }
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:41,代码来源:Cli.php

示例10: 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;
 }
开发者ID:nguyenduong127,项目名称:Project-dll.vn-,代码行数:32,代码来源:Cli.php

示例11: 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;
 }
开发者ID:quincia,项目名称:zf-cli,代码行数:29,代码来源:Cli.php

示例12: __construct

 function __construct($process_classes_folder)
 {
     $this->Logger = \Logger::getLogger('JobLauncher');
     $processes = @glob("{$process_classes_folder}/class.*Process.php");
     $options = array();
     if (count($processes) > 0) {
         foreach ($processes as $process) {
             $filename = basename($process);
             $directory = dirname($process);
             if (!file_exists($directory . "/" . $filename)) {
                 throw new \Exception(sprintf("File %s does not exist.", $directory . "/" . $filename));
             }
             include_once $directory . "/" . $filename;
             preg_match("/class.(.*)Process.php/s", $filename, $tmp);
             $process_name = $tmp[1];
             if (class_exists("{$process_name}Process")) {
                 $reflect = new \ReflectionClass("{$process_name}Process");
                 if ($reflect) {
                     if ($reflect->implementsInterface('Scalr\\System\\Pcntl\\ProcessInterface')) {
                         $options[$process_name] = $reflect->getProperty("ProcessDescription")->getValue($reflect->newInstance());
                     } else {
                         throw new \Exception("Class '{$process_name}Process' doesn't implement 'ProcessInterface'.", E_ERROR);
                     }
                 } else {
                     throw new \Exception("Cannot use ReflectionAPI for class '{$process_name}Process'", E_ERROR);
                 }
             } else {
                 throw new \Exception("'{$process}' does not contain definition for '{$process_name}Process'", E_ERROR);
             }
         }
     } else {
         throw new \Exception(_("No job classes found in {$process_classes_folder}"), E_ERROR);
     }
     $options["help"] = "Print this help";
     $options["piddir=s"] = "PID directory";
     $Getopt = new \Zend_Console_Getopt($options);
     try {
         $opts = $Getopt->getOptions();
     } catch (\Zend_Console_Getopt_Exception $e) {
         print "{$e->getMessage()}\n\n";
         die($Getopt->getUsageMessage());
     }
     if (in_array("help", $opts) || count($opts) == 0 || !$options[$opts[0]]) {
         print $Getopt->getUsageMessage();
         exit;
     } else {
         $this->ProcessName = $opts[0];
         /*
         if (in_array("piddir", $opts)) {
             $piddir = trim($Getopt->getOption("piddir"));
             if (substr($piddir, 0, 1) != '/') {
                 //$this->PIDDir = realpath($process_classes_folder . "/" . $piddir);
             } else {
                 //$this->PIDDir = $piddir;
             }
         }
         */
     }
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:59,代码来源:JobLauncher.php

示例13: _cliHelper

 /**
  * call handle cli function with params
  * 
  * @param array $_params
  */
 protected function _cliHelper($command, $_params)
 {
     $opts = new Zend_Console_Getopt(array($command => $command));
     $opts->setArguments($_params);
     ob_start();
     $this->_cli->handle($opts, false);
     $out = ob_get_clean();
     return $out;
 }
开发者ID:bitExpert,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:14,代码来源:CliTest.php

示例14: getOption

 /**
  * Get option value
  *
  * @param string $key
  * @param mixed $default
  *
  * @return mixed|null
  */
 public static function getOption($key, $default = null)
 {
     if (!static::$_getopt instanceof \Zend_Console_Getopt) {
         return $default;
     }
     $value = static::$_getopt->getOption($key);
     if (is_null($value)) {
         return $default;
     }
     return $value;
 }
开发者ID:Mohitsahu123,项目名称:magento-performance-toolkit,代码行数:19,代码来源:Cli.php

示例15: 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();
 }
开发者ID:rodrigofns,项目名称:ExpressoLivre3,代码行数:17,代码来源:Cli.php


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