本文整理汇总了PHP中Symfony\Component\Console\Helper\ProgressBar::getFormatDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP ProgressBar::getFormatDefinition方法的具体用法?PHP ProgressBar::getFormatDefinition怎么用?PHP ProgressBar::getFormatDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Helper\ProgressBar
的用法示例。
在下文中一共展示了ProgressBar::getFormatDefinition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createProgressBar
/**
* @param int $count
* @param int $minVerbosity
*
* @return ProgressBar
*/
public function createProgressBar($count, $minVerbosity = OutputInterface::VERBOSITY_NORMAL)
{
$stream = new NullOutput();
if ($this->applicationInput->hasOption('progress') && $this->applicationInput->getOption('progress')) {
if ($this->applicationOutput instanceof ConsoleOutput) {
if ($this->applicationOutput->getVerbosity() >= $minVerbosity) {
$stream = $this->applicationOutput->getErrorOutput();
}
}
}
$progress = new ProgressBar($stream, $count);
// add an additional space, in case logging is also enabled
$progress->setFormat($progress->getFormatDefinition('normal') . ' ');
$progress->start();
return $progress;
}
示例2: onCerberePreAction
/**
* @param CerberePreActionEvent $event
*/
public function onCerberePreAction(CerberePreActionEvent $event)
{
if ($max = count($event->getProjects())) {
// Returns and jump new line.
$this->output->getErrorOutput()->writeln('');
$format = " Project: %project%\n";
$format .= ProgressBar::getFormatDefinition('debug');
$progress = new ProgressBar($this->output, $max);
$progress->setFormat($format);
$progress->setRedrawFrequency(1);
$progress->setMessage('Action starts');
$this->progress = $progress;
}
}
示例3: main
public function main()
{
try {
/*
* PROPERTIES VALIDATION
*/
// check if the proxy flag has been set
$proxy = $this->getProject()->getUserProperty('proxy');
$proxy = $proxy !== null ? filter_var($proxy, FILTER_VALIDATE_BOOLEAN) : true;
// determine the url of the WSDL document
$wsdlUrl = $this->getProject()->getUserProperty('wsdl.url');
$wsdlUrl = $wsdlUrl ? $wsdlUrl : static::WSDL_URL;
/*
* PROXY CONFIGURATION
*/
// read the proxy configuration from the environment variables
$proxy = $proxy ? current(array_filter(array(getenv('HTTP_PROXY'), getenv('http_proxy')), 'strlen')) : null;
// prepare an empty url for the stream context
$streamContextProxyUrl = null;
// if the proxy is configured in the system
if ($proxy) {
// parse the WSDL url
$parsedWsdlPath = Url::createFromUrl($wsdlUrl);
// parse the proxy url
$proxy = Url::createFromUrl($proxy);
// if not fetching the wsdl file from filesystem and a proxy has been configured
if ($parsedWsdlPath->getScheme()->get() !== 'file') {
$streamContextProxyUrl = 'tcp://' . $proxy->getAuthority() . $proxy->getRelativeUrl();
libxml_set_streams_context(stream_context_get_default(array($proxy->getScheme()->get() => array('proxy' => $streamContextProxyUrl, 'request_fulluri' => true))));
}
}
/*
* INITIALIZATION
*/
// prepare the path to the generated code
$outputDir = $this->project->getBasedir() . '/src';
$output = new ConsoleOutput();
$progress = new ProgressBar($output, 100);
$progress->setFormat(ProgressBar::getFormatDefinition('normal') . ' %message%...');
$progress->setMessage('Starting');
$progress->start();
$progress->setMessage('Cleaning the environment');
// clean the output directory
array_map('unlink', glob($outputDir . '/*'));
$progress->advance(10);
/*
* GENERATION
*/
// prepare the generator configuration
$progress->setMessage('Configuring the generator');
$optionFeatures = array();
if ($proxy) {
/* @var \League\Url\UrlInterface $proxy */
$optionFeatures['proxy_host'] = $proxy->getHost()->get();
$optionFeatures['proxy_port'] = $proxy->getPort()->get();
}
$config = new Config($wsdlUrl, $outputDir);
$config->setNoTypeConstructor(true);
$config->setOptionFeatures($optionFeatures);
$config->setCreateAccessors(false);
$config->setWsdlCache(false);
$progress->advance(10);
// generate the code
$progress->setMessage('Generating the code');
$gen = new Generator();
$gen->generate($config);
$progress->advance(10);
/*
* FIX
*/
// the 'optionFeatures' configuration options is misused by the generator:
// it is correctly used as the default 'features' options of the service (its values are bitwised and put
// in the service class constructor), but it is also used as the '$options' argument of the \SoapClient
// class when it connects to the service to inspect it (hence the need to define the 'proxy_host' and
// 'proxy_port' keys). this makes the generated code clash, so we need to fix it, removing the unneeded
// values from the bitwise operation.
$defaultFeatures = array('SOAP_SINGLE_ELEMENT_ARRAYS', 'SOAP_WAIT_ONE_WAY_CALLS');
// fix the option 'features' management
$fileContent = file_get_contents("{$outputDir}/ClabService.php");
$fileContent = preg_replace('/(\\$options\\[\'features\'\\] = ).*/', '$1' . implode(' | ', $defaultFeatures) . ';', $fileContent, -1, $count);
// if no features option has been found, they must be added manually
if ($count === 0) {
$fileContent = preg_replace('/parent::__construct/', "if (isset(\$options['features']) == false) {\n\$options['features'] = " . implode(' | ', $defaultFeatures) . ";\n}\n\nparent::__construct", $fileContent, -1, $count);
}
file_put_contents("{$outputDir}/ClabService.php", $fileContent);
/*
* LICENSE MANAGEMENT
*/
$progress->setMessage('Applying the license to the generated files');
// read the license header
$licenseHeader = file_get_contents($this->project->getBasedir() . '/resources/license_header.txt');
// print the license on top of every file
foreach (glob($outputDir . '/*.php') as $sourceFile) {
$fileContent = file_get_contents($sourceFile);
$fileContent = preg_replace('/^(<\\?php)/', "\$1\n\n" . $licenseHeader, $fileContent);
file_put_contents($sourceFile, $fileContent);
}
unset($sourceFile);
$progress->advance(10);
/*
//.........这里部分代码省略.........