本文整理汇总了PHP中Console_CommandLine::accept方法的典型用法代码示例。如果您正苦于以下问题:PHP Console_CommandLine::accept方法的具体用法?PHP Console_CommandLine::accept怎么用?PHP Console_CommandLine::accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Console_CommandLine
的用法示例。
在下文中一共展示了Console_CommandLine::accept方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Entry-point for Erebot.
*
* \return
* This method never returns.
* Instead, the program exits with an appropriate
* return code when Erebot is stopped.
*/
public static function run()
{
// Apply patches.
\Erebot\Patches::patch();
// Load the configuration for the Dependency Injection Container.
$dic = new \Symfony\Component\DependencyInjection\ContainerBuilder();
$dic->setParameter('Erebot.src_dir', __DIR__);
$loader = new \Symfony\Component\DependencyInjection\Loader\XmlFileLoader($dic, new \Symfony\Component\Config\FileLocator(getcwd()));
$dicConfig = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'defaults.xml';
$dicCwdConfig = getcwd() . DIRECTORY_SEPARATOR . 'defaults.xml';
if (!strncasecmp(__FILE__, 'phar://', 7)) {
if (!file_exists($dicCwdConfig)) {
copy($dicConfig, $dicCwdConfig);
}
$dicConfig = $dicCwdConfig;
} elseif (file_exists($dicCwdConfig)) {
$dicConfig = $dicCwdConfig;
}
$loader->load($dicConfig);
// Determine availability of PHP extensions
// needed by some of the command-line options.
$hasPosix = in_array('posix', get_loaded_extensions());
$hasPcntl = in_array('pcntl', get_loaded_extensions());
$logger = $dic->get('logging');
$localeGetter = $dic->getParameter('i18n.default_getter');
$coreTranslatorCls = $dic->getParameter('core.classes.i18n');
$translator = new $coreTranslatorCls("Erebot\\Core");
$categories = array('LC_MESSAGES', 'LC_MONETARY', 'LC_TIME', 'LC_NUMERIC');
foreach ($categories as $category) {
$locales = call_user_func($localeGetter);
$locales = empty($locales) ? array() : array($locales);
$localeSources = array('LANGUAGE' => true, 'LC_ALL' => false, $category => false, 'LANG' => false);
foreach ($localeSources as $source => $multiple) {
if (!isset($_SERVER[$source])) {
continue;
}
if ($multiple) {
$locales = explode(':', $_SERVER[$source]);
} else {
$locales = array($_SERVER[$source]);
}
break;
}
$translator->setLocale($translator->nameToCategory($category), $locales);
}
// Also, include some information about the version
// of currently loaded PHAR modules, if any.
$version = 'dev-master';
if (!strncmp(__FILE__, 'phar://', 7)) {
$phar = new \Phar(\Phar::running(true));
$md = $phar->getMetadata();
$version = $md['version'];
}
if (defined('Erebot_PHARS')) {
$phars = unserialize(Erebot_PHARS);
ksort($phars);
foreach ($phars as $module => $metadata) {
if (strncasecmp($module, 'Erebot_Module_', 14)) {
continue;
}
$version .= "\n with {$module} version {$metadata['version']}";
}
}
\Console_CommandLine::registerAction('StoreProxy', '\\Erebot\\Console\\StoreProxyAction');
$parser = new \Console_CommandLine(array('name' => 'Erebot', 'description' => $translator->gettext('A modular IRC bot written in PHP'), 'version' => $version, 'add_help_option' => true, 'add_version_option' => true, 'force_posix' => false));
$parser->accept(new \Erebot\Console\MessageProvider());
$parser->renderer->options_on_different_lines = true;
$defaultConfigFile = getcwd() . DIRECTORY_SEPARATOR . 'Erebot.xml';
$parser->addOption('config', array('short_name' => '-c', 'long_name' => '--config', 'description' => $translator->gettext('Path to the configuration file to use instead ' . 'of "Erebot.xml", relative to the current ' . 'directory.'), 'help_name' => 'FILE', 'action' => 'StoreString', 'default' => $defaultConfigFile));
$parser->addOption('daemon', array('short_name' => '-d', 'long_name' => '--daemon', 'description' => $translator->gettext('Run the bot in the background (daemon).' . ' [requires the POSIX and pcntl extensions]'), 'action' => 'StoreTrue'));
$noDaemon = new \Erebot\Console\ParallelOption('no_daemon', array('short_name' => '-n', 'long_name' => '--no-daemon', 'description' => $translator->gettext('Do not run the bot in the background. ' . 'This is the default, unless the -d option ' . 'is used or the bot is configured otherwise.'), 'action' => 'StoreProxy', 'action_params' => array('option' => 'daemon')));
$parser->addOption($noDaemon);
$parser->addOption('pidfile', array('short_name' => '-p', 'long_name' => '--pidfile', 'description' => $translator->gettext("Store the bot's PID in this file."), 'help_name' => 'FILE', 'action' => 'StoreString', 'default' => null));
$parser->addOption('group', array('short_name' => '-g', 'long_name' => '--group', 'description' => $translator->gettext('Set group identity to this GID/group during ' . 'startup. The default is to NOT change group ' . 'identity, unless configured otherwise.' . ' [requires the POSIX extension]'), 'help_name' => 'GROUP/GID', 'action' => 'StoreString', 'default' => null));
$parser->addOption('user', array('short_name' => '-u', 'long_name' => '--user', 'description' => $translator->gettext('Set user identity to this UID/username during ' . 'startup. The default is to NOT change user ' . 'identity, unless configured otherwise.' . ' [requires the POSIX extension]'), 'help_name' => 'USER/UID', 'action' => 'StoreString', 'default' => null));
try {
$parsed = $parser->parse();
} catch (\Exception $exc) {
$parser->displayError($exc->getMessage());
exit(1);
}
// Parse the configuration file.
$config = new \Erebot\Config\Main($parsed->options['config'], \Erebot\Config\Main::LOAD_FROM_FILE, $translator);
$coreCls = $dic->getParameter('core.classes.core');
$bot = new $coreCls($config, $translator);
$dic->set('bot', $bot);
// Use values from the XML configuration file
// if there is no override from the command line.
$overrides = array('daemon' => 'mustDaemonize', 'group' => 'getGroupIdentity', 'user' => 'getUserIdentity', 'pidfile' => 'getPidfile');
foreach ($overrides as $option => $func) {
if ($parsed->options[$option] === null) {
$parsed->options[$option] = $config->{$func}();
//.........这里部分代码省略.........