本文整理汇总了PHP中Symfony\Component\Console\Style\SymfonyStyle::block方法的典型用法代码示例。如果您正苦于以下问题:PHP SymfonyStyle::block方法的具体用法?PHP SymfonyStyle::block怎么用?PHP SymfonyStyle::block使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Style\SymfonyStyle
的用法示例。
在下文中一共展示了SymfonyStyle::block方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->io = new SymfonyStyle($input, $output);
$this->sort = $input->getOption('sort');
$this->sleepTime = $input->getOption('sleepTime');
if (!$input->hasOption('sleepTime') && $output->getVerbosity() >= OutputInterface::VERBOSITY_NORMAL) {
$this->sleepTime = 25;
}
// Transform milliseconds in microseconds for usleep()
$this->sleepTime = $this->sleepTime * 1000;
$this->numberOfCodesToGenerate = $input->getOption('amount');
// The length of each outputted code
$this->codeLength = $input->getOption('length');
// All possible chars. By default, 'A' to 'Z' and '0' to '9'
$this->possibleChars = str_split($input->getOption('characters'));
$baseNumberOfChars = count($this->possibleChars);
$this->possibleChars = array_unique($this->possibleChars);
// If there's an error here, we'll say it later
$maxPossibleNumberOfCombinations = pow(count($this->possibleChars), $this->codeLength);
if ($maxPossibleNumberOfCombinations < $this->numberOfCodesToGenerate) {
$this->io->error(sprintf('Cannot generate %s combinations because there are only %s combinations possible', number_format($this->numberOfCodesToGenerate, 0, '', ' '), number_format($maxPossibleNumberOfCombinations, 0, '', ' ')));
return 1;
} else {
$this->io->block(sprintf('Generating %s combinations.', number_format($this->numberOfCodesToGenerate, 0, '', ' ')), null, 'info');
if ($maxPossibleNumberOfCombinations > $this->numberOfCodesToGenerate) {
$this->io->block(sprintf('Note: If you need you can generate %s more combinations (with a maximum of %s).', number_format($maxPossibleNumberOfCombinations - $this->numberOfCodesToGenerate, 0, '', ' '), number_format($maxPossibleNumberOfCombinations, 0, '', ' ')), null, 'comment');
}
}
$this->io->block('Available characters:');
$this->io->block(implode('', $this->possibleChars), null, 'info');
$codesList = $this->doGenerate();
$outputFile = $input->getOption('output');
if ($outputFile) {
$save = true;
if (file_exists($outputFile)) {
$save = $this->io->confirm(sprintf('File %s exists. Erase it?', $outputFile), false);
}
if ($save) {
$this->io->block(sprintf('Output results to %s', $outputFile), null, 'info');
if (!file_put_contents($outputFile, implode("\n", $codesList))) {
throw new \Exception(sprintf('Could not write to %s...', $outputFile));
}
}
} else {
$this->io->text($codesList);
}
if ($baseNumberOfChars !== count($this->possibleChars)) {
$this->io->warning(sprintf('We detected that there were duplicate characters in "%s", so we removed them.', $input->getOption('characters')));
}
return 0;
}
示例2: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->title('OpenCFP');
$io->section('Creating User');
$user = $this->createUser(['first_name' => $input->getOption('first_name'), 'last_name' => $input->getOption('last_name'), 'password' => $input->getOption('password'), 'email' => $input->getOption('email')]);
if (false === $user) {
$io->error('User Already Exists!');
return 1;
}
$io->block('Account was created');
if ($input->getOption('admin')) {
$io->block('Promoting to admin.');
$this->promote($user);
}
$io->success('User Created!');
}
示例3: testLongWordsBlockWrapping
public function testLongWordsBlockWrapping()
{
$word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygon';
$wordLength = strlen($word);
$maxLineLength = SymfonyStyle::MAX_LINE_LENGTH - 3;
$this->command->setCode(function (InputInterface $input, OutputInterface $output) use($word) {
$sfStyle = new SymfonyStyle($input, $output);
$sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' § ', false);
});
$this->tester->execute(array(), array('interactive' => false, 'decorated' => false));
$expectedCount = (int) ceil($wordLength / $maxLineLength) + (int) ($wordLength > $maxLineLength - 5);
$this->assertSame($expectedCount, substr_count($this->tester->getDisplay(true), ' § '));
}
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->io = new SymfonyStyle($input, $output);
$this->io->block('Running server...');
$verbosity = $this->io->getVerbosity();
switch ($verbosity) {
case 16:
$verbosity = 'quiet';
break;
case 32:
$verbosity = 'normal';
break;
case 64:
$verbosity = 'verbose';
break;
case 128:
$verbosity = 'very_verbose';
break;
case 256:
$verbosity = 'debug';
break;
}
$this->io->note('Verbosity is "' . $verbosity . '". To set verbosity, add "-v", "-vv" or "-vvv" end the end of this command.');
$this->socketPort = $this->getContainer()->getParameter('socket_port');
$em = $this->getContainer()->get('doctrine.orm.default_entity_manager');
$logger = $this->getContainer()->get('logger');
$socketUrl = $this->getContainer()->getParameter('socket_server_url');
$webUrl = $this->getContainer()->getParameter('web_server_url');
$webHooks = $em->getRepository('AppBundle:WebHook')->findAll();
$logger->info(count($webHooks) . ' webHook(s)');
$server = new Server($em, $webHooks, $webUrl, $socketUrl, $logger);
$this->killExistingSocketServer();
$ioServer = IoServer::factory(new HttpServer(new WsServer($server)), $this->socketPort);
$logger->info('Run socket server on port ' . $this->socketPort . '...');
$ioServer->run();
}
示例5: function
<?php
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
//Ensure that all lines are aligned to the begin of the first line in a very long line block
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyle($input, $output);
$output->block('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', 'CUSTOM', 'fg=white;bg=green', 'X ', true);
};
示例6: function
<?php
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
// ensure long words are properly wrapped in blocks
return function (InputInterface $input, OutputInterface $output) {
$word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygon';
$sfStyle = new SymfonyStyle($input, $output);
$sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' § ', false);
};
示例7: function
<?php
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
//Ensure has single blank line between blocks
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyle($input, $output);
$output->warning('Warning');
$output->caution('Caution');
$output->error('Error');
$output->success('Success');
$output->note('Note');
$output->block('Custom block', 'CUSTOM', 'fg=white;bg=green', 'X ', true);
};
示例8: function
<?php
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
//Ensure that all lines are aligned to the begin of the first line in a multi-line block
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyle($input, $output);
$output->block(array('Custom block', 'Second custom block line'), 'CUSTOM', 'fg=white;bg=green', 'X ', true);
};
示例9: title
/**
* Prints out a pretty title.
*
* @param string $title
*/
protected function title($title)
{
$this->output->block($title, null, 'fg=black;bg=cyan', ' ', false);
}
示例10: checkBackup
/**
* Check single backup-configuration.
*
* @param PluginRegistry $plugins
* @param SymfonyStyle $io
* @param string $name
* @param array $backup
*
* @return bool
*/
private function checkBackup(PluginRegistry $plugins, SymfonyStyle $io, $name, array $backup)
{
$io->section('Backup: ' . $name);
if (!$plugins->has($backup['plugin'])) {
$io->warning(sprintf('Plugin "%s" not found', $backup['plugin']));
return false;
}
$optionsResolver = new OptionsResolver();
$plugins->getPlugin($backup['plugin'])->configureOptionsResolver($optionsResolver);
try {
$parameter = $optionsResolver->resolve($backup['parameter']);
} catch (InvalidArgumentException $e) {
$io->warning(sprintf('Parameter not valid' . PHP_EOL . PHP_EOL . 'Message: "%s"', $e->getMessage()));
return false;
}
$io->write('Parameter:');
$messages = array_filter(explode("\r\n", Yaml::dump($parameter)));
$io->block($messages, null, null, ' ');
$io->writeln('OK');
return true;
}
示例11: execute
/**
* Executes the current command.
*
* This method is not abstract because you can use this class
* as a concrete class. In this case, instead of defining the
* execute() method, you set the code to execute by passing
* a Closure to the setCode() method.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return null|int null or 0 if everything went fine, or an error code
*
* @see setCode()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$styleHelper = new SymfonyStyle($input, $output);
$validatorFactory = new ValidatorFactoryImplementation();
$validators = $validatorFactory->getMessageValidator();
$commitMessage = file_get_contents($input->getArgument(self::ARGUMENT_COMMIT_MESSAGE_FILE));
$commentCharacter = $input->getOption(self::OPTION_COMMENT_CHAR);
$ignorePatterns = $input->getOption(self::OPTION_IGNORE);
foreach ($ignorePatterns as $ignorePattern) {
if (preg_match($ignorePattern, $commitMessage)) {
return 0;
}
}
$safeCommitMessage = preg_replace('/' . preg_quote($commentCharacter) . '.*/', '', $commitMessage);
$message = new MessageImplementation($safeCommitMessage);
$validators->validate($message);
if (count($message->getStatuses()) < 1) {
return 0;
}
$statusList = [];
$isPositive = true;
/** @var Status $status */
foreach ($message->getStatuses() as $status) {
$statusList[] = $status->getMessage() . ' (' . $status->getDetailsUrl() . ')';
$isPositive = $status->isPositive() && $isPositive;
}
if ($isPositive) {
return 0;
}
$styleHelper->error('Incorrectly formatted commit message');
$styleHelper->listing($statusList);
$styleHelper->section('Your Commit Message');
$styleHelper->block($commitMessage);
$styleHelper->warning('A commit has not been created');
return 1;
}