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


PHP Zend_Console_Getopt::getOption方法代码示例

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


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

示例1: addAction

 /**
  * Add a partner
  *
  * This is the add partner method. It literally does what it say.
  * It adds a partner.
  *
  * @return void
  */
 public function addAction()
 {
     $this->_helper->viewRenderer->setViewSuffix('txt');
     // The options we are accepting for adding
     $options = new Zend_Console_Getopt(array('first-name|fn=s' => $this->tr->_('FIRSTNAME'), 'last-name|ln=s' => $this->tr->_('LASTNAME'), 'email|e=s' => $this->tr->_('EMAIL_USERNAME'), 'company|c=s' => $this->tr->_('COMPANY')));
     try {
         $options->parse();
     } catch (Zend_Console_Getopt_Exception $e) {
         $this->view->message = $e->getUsageMessage();
         $this->render();
         return;
     }
     if ($options->getOption('first-name') == '' || $options->getOption('last-name') == '' || $options->email == '' || $options->company == '') {
         $this->view->message = $options->getUsageMessage();
         return;
     }
     $partner_first_name = $options->getOption('first-name');
     $partner_last_name = $options->getOption('last-name');
     $partner_email = $options->email;
     $partner_company = $options->company;
     $submit_data = array('firstname' => $partner_first_name, 'lastname' => $partner_last_name, 'email' => $partner_email, 'company' => $partner_company);
     $model = new Default_Model_Partner();
     try {
         $model->add($submit_data);
         $this->view->message = 'Successfully added partner: ' . $partner_email . PHP_EOL;
     } catch (RuntimeException $e) {
         $this->view->message = 'Error adding partner: ' . $partner_email . '. ' . $e->getMessage() . PHP_EOL;
     }
 }
开发者ID:crlang44,项目名称:frapi,代码行数:37,代码来源:PartnerController.php

示例2: __construct

 /**
  * 构造函数,初始化日志文件目录。
  */
 protected function __construct()
 {
     try {
         $console = new Zend_Console_Getopt(array('logroot|l=s' => 'the Log Server root directory', 'logdir|d=s' => 'this log file directory', 'logfile|f=s' => 'the log files', 'delay|a=i' => 'delay timestamp', 'start|s=s' => 'start datetime', 'end|e=s' => 'end datetime'));
         if (!$console->getOptions()) {
             throw new ZtChart_Model_Monitor_Console_Exception($console->getUsageMessage());
         }
         if (null !== ($logServerRootDirectory = $console->getOption('l'))) {
             foreach (array_diff(scandir($logServerRootDirectory), array('.', '..')) as $directory) {
                 $this->_logDirectories[] = realpath($logServerRootDirectory) . DIRECTORY_SEPARATOR . $directory;
             }
         }
         if (null !== ($logDirectories = $console->getOption('d'))) {
             $this->_logDirectories += $logDirectories;
         }
         if (null !== ($logFiles = $console->getOption('f'))) {
             $this->_logFiles = explode(' ', $logFiles);
         }
         if (null !== ($delayTimestamp = $console->getOption('a'))) {
             $this->_delayTimestamp = $delayTimestamp;
         }
         if (null !== ($startTimestamp = $console->getOption('s'))) {
             $this->_startTimestamp = $startTimestamp;
         }
         if (null !== ($endTimestamp = $console->getOption('e'))) {
             $this->_endTimestamp = $endTimestamp;
         }
     } catch (Zend_Console_Getopt_Exception $e) {
         throw new ZtChart_Model_Monitor_Console_Exception($e->getMessage());
     }
     $this->_console = $console;
 }
开发者ID:starflash,项目名称:ZtChart-ZF1-Example,代码行数:35,代码来源:Console.php

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

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

示例5: compileSchema

 public function compileSchema()
 {
     if (!$this->opts->getOption('dest')) {
         throw new RuntimeException("Specify destination folder (--dest PATH)");
     }
     if (!$this->opts->getOption('schema')) {
         throw new RuntimeException("Specify path to XML Schema file (--schema PATH)");
     }
     $schema = $this->opts->getOption('schema');
     if (!file_exists($schema)) {
         throw new RuntimeException("Schema file " . $schema . " is not found");
     }
     $dest = $this->opts->getOption('dest');
     $this->legko->compileSchema($schema, $dest);
     $this->println("Bindings successfully generated in " . realpath($dest));
 }
开发者ID:beanworks,项目名称:quickbooks-online-v3-sdk,代码行数:16,代码来源:legko.php

示例6: getInstanceOptions

 /**
  * method to sync the options received from cli with the possible options
  * if options is mandatory and not received return false
  * 
  * @param type $possibleOptions
  * 
  * @return mixed array of options if all mandatory options received, else false
  */
 public function getInstanceOptions($possibleOptions = null)
 {
     if (is_null($possibleOptions)) {
         $possibleOptions = array('type' => false, 'stamp' => false, 'path' => "./", 'parser' => 'fixed');
     }
     $options = array();
     //Retrive  the command line  properties
     //		foreach($this->options->getRemainingArgs() as  $cmdLineArg) {
     //			$seperatedCmdStr = !strpos('=',$cmdLineArg) ? split("=", $cmdLineArg) : split(" ", $cmdLineArg);
     //			$inLineOpt = isset($seperatedCmdStr[1]) ?  $seperatedCmdStr[1] : true;
     //			foreach (array_reverse(split("\.", $seperatedCmdStr[0])) as $field) {
     //				$inLineOpt = array( $field => $inLineOpt);
     //			}
     //			$options['cmd_opts'] = array_merge_recursive( (isset($options['cmd_opts']) ? $options['cmd_opts'] : array() ), $inLineOpt );
     //		}
     foreach ($possibleOptions as $key => $defVal) {
         $options[$key] = $this->options->getOption($key);
         if (is_null($options[$key])) {
             if (!$defVal) {
                 $this->addOutput("Error: No {$key} selected");
                 return false;
             } else {
                 if (true !== $defVal) {
                     $options[$key] = $defVal;
                 } else {
                     unset($options[$key]);
                 }
             }
         }
     }
     return $options;
 }
开发者ID:ngchie,项目名称:system,代码行数:40,代码来源:Cli.php

示例7: createProject

 /**
  * Creates the new project
  * @throws Exception
  */
 public function createProject()
 {
     $force = !!$this->console->getOption('force');
     $realAppPath = realpath($this->appPath) . DIRECTORY_SEPARATOR;
     $realLibraryPath = realpath(dirname(__FILE__) . '/../') . DIRECTORY_SEPARATOR;
     $libraryPath = 'Library/';
     while (!file_exists($this->appPath . $libraryPath) && strpos($realAppPath, $realLibraryPath) === 0) {
         $libraryPath = '../' . $libraryPath;
     }
     foreach ($this->projectFiles as $projectFile => $projectFileValue) {
         if (is_int($projectFile)) {
             $projectFile = $projectFileValue;
             $projectFileValue = array();
         }
         if (file_exists($this->appPath . $projectFile) && !$force) {
             throw new Exception('Project file "' . $projectFile . '" already exists failure.');
         }
         if (substr($projectFile, -1) === '/') {
             if (!file_exists($this->appPath . $projectFile)) {
                 mkdir($this->appPath . $projectFile, 0777, !empty($projectFileValue['recursive']));
             }
             if (isset($projectFileValue['chmod'])) {
                 $old = umask(0);
                 chmod($this->appPath . $projectFile, $projectFileValue['chmod']);
                 umask($old);
             }
         } else {
             $fileContent = isset($projectFileValue['content']) ? $projectFileValue['content'] : '';
             $fileContent = str_replace(array('%app%', '%appPath%', '%libraryPath%'), array($this->app, $this->appPath, $libraryPath), $fileContent);
             file_put_contents($this->appPath . $projectFile, $fileContent);
         }
     }
 }
开发者ID:nvdnkpr,项目名称:Enlight,代码行数:37,代码来源:lighter.php

示例8: _getOption

 /**
  * Get option value by name
  *
  * @param string $sName
  * @return string
  */
 protected final function _getOption($sName)
 {
     $sOption = $this->_oGetopt->getOption($sName);
     if (is_null($sOption) && !is_null($this->_aExpectedOptions[$sName]['default'])) {
         $sOption = $this->_aExpectedOptions[$sName]['default'];
     }
     return $sOption;
 }
开发者ID:pansot2,项目名称:PadCMS-backend,代码行数:14,代码来源:Abstract.php

示例9: __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

示例10: array

 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:recipe,项目名称:scalr,代码行数:57,代码来源:JobLauncher.php

示例11: 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')) {
        create(APPLICATION, array($applicationName));
        exit;
    }
    if ($opts->getOption('h')) {
        echo $e->getUsageMessage();
        exit;
    }
}
开发者ID:rodrigofns,项目名称:ExpressoLivre3,代码行数:19,代码来源:tn.php

示例12: route

 public function route(Zend_Controller_Request_Abstract $dispatcher)
 {
     try {
         $opts = new Zend_Console_Getopt(array('help|h' => 'prints this usage information', 'action|a=s' => 'action name (default: index)', 'controller|c=s' => 'controller name  (default: index)', 'verbose|v' => 'explain what is being done'));
         $opts->parse();
     } catch (Zend_Console_Getopt_Exception $e) {
         echo $e->getMessage() . "\n\n" . $e->getUsageMessage();
         exit(1);
     }
     if ($opts->getOption("help")) {
         echo $opts->getUsageMessage();
         exit;
     }
     if (!$opts->getOption("action")) {
         $opts->setOption("action", "index");
     }
     if (!$opts->getOption("controller")) {
         $opts->setOption("controller", "index");
     }
     $dispatcher->setControllerName($opts->getOption("controller"))->setActionName($opts->getOption("action"));
 }
开发者ID:henvic,项目名称:MediaLab,代码行数:21,代码来源:Cli.php

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

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

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


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