本文整理汇总了PHP中Symfony\Component\Console\Output\StreamOutput::writeln方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamOutput::writeln方法的具体用法?PHP StreamOutput::writeln怎么用?PHP StreamOutput::writeln使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Output\StreamOutput
的用法示例。
在下文中一共展示了StreamOutput::writeln方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
if (NULL !== ($file = $input->getOption('file'))) {
if (is_file($file) && !$input->getOption('overwrite')) {
$output->writeln(sprintf('File <info>%s</info> already exists, use option <comment>-o</comment> to overwrite it.', $file));
return;
}
$backup = $output;
$fp = fopen($file, 'wb');
$output = new StreamOutput($fp);
}
$request = new HttpRequest(new Uri('http://test.me/'));
$this->requestScope->enter($request);
try {
$output->writeln('routes:');
$routes = $this->router->getRoutes($this->context)->getSortedRoutes();
foreach (array_reverse($routes) as $name => $route) {
$output->writeln(sprintf(' %s:', $name));
foreach (explode("\n", trim(Yaml::dump($route->toArray($this->context), 100))) as $line) {
$output->writeln(sprintf(' %s', $line));
}
}
} finally {
$this->requestScope->leave($request);
}
if (isset($fp) && is_resource($fp)) {
@fclose($fp);
$backup->writeln(sprintf('Config dumped to <info>%s</info>', $file));
}
}
示例2: run
/**
* {@inheritDoc}
*/
public function run(OutputInterface $output)
{
/** @type DebugFormatterHelper $debugFormatter */
$debugFormatter = $this->getHelperSet()->get('debug_formatter');
$arguments = $this->resolveProcessArgs();
$builder = new ProcessBuilder($arguments);
$process = $builder->getProcess();
if (null !== ($dispatcher = $this->getEventDispatcher())) {
$event = new PreExecuteEvent($this, $process);
$dispatcher->dispatch(Event::PRE_EXECUTE, $event);
if ($event->isPropagationStopped()) {
return true;
}
}
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERY_VERBOSE) {
$output->writeln(sprintf(' // Setting timeout for %d seconds.', $this->getParameter('timeout')));
}
$process->setTimeout($this->getParameter('timeout') !== 0 ? $this->getParameter('timeout') : null);
if ($this->hasParameter('cwd')) {
$process->setWorkingDirectory($this->getParameter('cwd'));
}
if (get_class($this) === 'Bldr\\Block\\Execute\\Task\\ExecuteTask') {
$output->writeln(['', sprintf(' <info>[%s]</info> - <comment>Starting</comment>', $this->getName()), '']);
}
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE || $this->getParameter('dry_run')) {
$output->writeln(' // ' . $process->getCommandLine());
}
if ($this->getParameter('dry_run')) {
return true;
}
if ($this->hasParameter('output')) {
$append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
$stream = fopen($this->getParameter('output'), $append);
$output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
}
$output->writeln("<fg=blue>==============================\n</fg=blue>");
$output->writeln($debugFormatter->start(spl_object_hash($process), $process->getCommandLine()));
$process->run(function ($type, $buffer) use($output, $debugFormatter, $process) {
if ($this->getParameter('raw')) {
$output->write($buffer, false, OutputInterface::OUTPUT_RAW);
return;
}
$output->write($debugFormatter->progress(spl_object_hash($process), $buffer, Process::ERR === $type));
});
$output->writeln($debugFormatter->stop(spl_object_hash($process), $process->getCommandLine(), $process->isSuccessful()));
$output->writeln("<fg=blue>==============================</fg=blue>");
if (null !== $dispatcher) {
$event = new PostExecuteEvent($this, $process);
$dispatcher->dispatch(Event::POST_EXECUTE, $event);
}
if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) {
throw new TaskRuntimeException($this->getName(), $process->getErrorOutput());
}
}
示例3: testDoWrite
public function testDoWrite()
{
$output = new StreamOutput($this->stream);
$output->writeln('foo');
rewind($output->getStream());
$this->assertEquals('foo' . PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
}
示例4: testFormattedEscapedOutput
public function testFormattedEscapedOutput()
{
$output = new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, true, null);
$output->writeln('<info>' . OutputFormatter::escape('<error>some error</error>') . '</info>');
rewind($output->getStream());
$this->assertSame("[32m<error>some error</error>[39m" . PHP_EOL, stream_get_contents($output->getStream()));
}
示例5: getIdephixMock
public function getIdephixMock($targets, $targetName)
{
$this->output = fopen("php://memory", 'r+');
$output = new StreamOutput($this->output);
$currentTarget = new Config($targets[$targetName]);
$sshClient = new SshClient(new FakeSsh2Proxy($this));
$sshClient->setParameters($currentTarget->get('ssh_params'));
$sshClient->setHost(current($currentTarget->get('hosts')));
$sshClient->connect();
$idx = $this->getMock('\\Idephix\\IdephixInterface');
$idx->sshClient = $sshClient;
$idx->output = $output;
$idx->expects($this->any())->method('getCurrentTarget')->will($this->returnValue($currentTarget));
$idx->expects($this->any())->method('getCurrentTargetName')->will($this->returnValue($targetName));
$idx->expects($this->any())->method('local')->will($this->returnCallback(function ($cmd) use($output) {
$output->writeln('Local: ' . $cmd);
}));
$idx->expects($this->any())->method('remote')->will($this->returnCallback(function ($cmd) use($output) {
$output->writeln('Remote: ' . $cmd);
}));
return $idx;
}
示例6: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$instance = $this->instances->find(Instance::makeId($input->getOption('root'), $input->getOption('name')));
if (!$instance) {
throw new \Exception("Failed to locate instance: " . Instance::makeId($input->getOption('root'), $input->getOption('name')));
}
$prefix = $input->getOption('prefix');
$dsnParts = \DB\DSN::parseDSN($instance->getDsn());
$output_file_path = $input->getOption('output-file');
if ($output_file_path != '') {
$output_file = fopen($output_file_path, "w");
$output = new StreamOutput($output_file);
}
$envVars = array("{$prefix}URL" => $instance->getUrl(), "{$prefix}ROOT" => $instance->getRoot(), "{$prefix}DB_DSN" => $instance->getDsn(), "{$prefix}DB_USER" => $dsnParts['username'], "{$prefix}DB_PASS" => $dsnParts['password'], "{$prefix}DB_HOST" => $dsnParts['hostspec'], "{$prefix}DB_PORT" => $dsnParts['port'], "{$prefix}DB_NAME" => $dsnParts['database'], "{$prefix}DB_ARGS" => $instance->getDatasource() ? $instance->getDatasource()->toMySQLArguments() : '');
foreach ($envVars as $var => $value) {
$output->writeln($var . '=' . escapeshellarg($value));
}
// $output->writeln('export ' . implode(' ', array_keys($envVars)));
}
示例7: updateAction
/**
* @Request(csrf=true)
*/
public function updateAction()
{
if (!($file = App::session()->get('system.update'))) {
App::abort(400, __('You may not call this step directly.'));
}
App::session()->remove('system.update');
return App::response()->stream(function () use($file) {
$output = new StreamOutput(fopen('php://output', 'w'));
try {
if (!file_exists($file) || !is_file($file)) {
throw new \RuntimeException('File does not exist.');
}
$updater = new SelfUpdater($output);
$updater->update($file);
} catch (\Exception $e) {
$output->writeln(sprintf("\n<error>%s</error>", $e->getMessage()));
$output->write("status=error");
}
});
}
示例8: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$locale = $input->getOption('locale');
if (empty($locale)) {
$locale = 'en_US';
}
$domain = $input->getOption('domain');
$bundle = $input->getOption('bundle');
$log = $input->getOption('logfile');
$loader = $this->getContainer()->get('mautic.translation.loader');
$factory = $this->getContainer()->get('mautic.factory');
$viewsOnly = $input->getOption('only-views');
$dupsOnly = $input->getOption('only-dups');
$bundles = $factory->getMauticBundles(true);
if (!empty($log)) {
$logfile = fopen($log, 'w+');
$output = new StreamOutput($logfile, null, false, new OutputFormatter(false));
}
if (!empty($bundle)) {
if (!isset($bundles[$bundle])) {
$output->writeln('Bundle not found');
return;
}
$bundles = [$bundles[$bundle]];
}
// Load defined messages
$currentCatalogue = new MessageCatalogue($locale);
// Extract used messages from Views
$extractedCatalogue = new MessageCatalogue($locale);
$phpFormExtractor = new PhpFormTranslationExtractor();
foreach ($bundles as $bundle) {
if (!$dupsOnly) {
if (file_exists($bundle['directory'] . '/Views')) {
$phpFormExtractor->extract($bundle['directory'] . '/Views', $extractedCatalogue);
$this->getContainer()->get('translation.extractor')->extract($bundle['directory'] . '/Views', $extractedCatalogue);
}
if (!$viewsOnly) {
$directories = ['/Form/Type', '/EventListener', '/Model', '/EventListener', '/Controller'];
foreach ($directories as $d) {
if (file_exists($bundle['directory'] . $d)) {
$phpFormExtractor->extract($bundle['directory'] . $d, $extractedCatalogue);
$this->getContainer()->get('translation.extractor')->extract($bundle['directory'] . $d, $extractedCatalogue);
}
}
}
}
if (is_dir($bundle['directory'] . '/Translations')) {
$currentCatalogue = $loader->load(null, $locale, $domain);
}
}
// Merge defined and extracted messages to get all message ids
$mergeOperation = new MergeOperation($extractedCatalogue, $currentCatalogue);
$allMessages = $mergeOperation->getResult()->all($domain);
if (null !== $domain) {
$allMessages = [$domain => $allMessages];
}
// No defined or extracted messages
if (empty($allMessages) || null !== $domain && empty($allMessages[$domain])) {
$outputMessage = sprintf('<info>No defined or extracted messages for locale "%s"</info>', $locale);
if (null !== $domain) {
$outputMessage .= sprintf(' <info>and domain "%s"</info>', $domain);
}
$output->writeln($outputMessage);
return;
}
/** @var \Symfony\Component\Console\Helper\Table $table */
$table = new Table($output);
// Display header line
$headers = ['State(s)', 'Id', sprintf('Message Preview (%s)', $locale)];
$table->setHeaders($headers);
$duplicateCheck = [];
// Iterate all message ids and determine their state
foreach ($allMessages as $domain => $messages) {
foreach (array_keys($messages) as $messageId) {
$value = $currentCatalogue->get($messageId, $domain);
$duplicateKey = strtolower($value);
if (!isset($duplicateCheck[$duplicateKey])) {
$duplicateCheck[$duplicateKey] = [];
}
$duplicateCheck[$duplicateKey][] = ['id' => $messageId, 'domain' => $domain];
$states = [];
if ($extractedCatalogue->defines($messageId, $domain)) {
if (!$currentCatalogue->defines($messageId, $domain)) {
$states[] = self::MESSAGE_MISSING;
}
} elseif ($currentCatalogue->defines($messageId, $domain)) {
$states[] = self::MESSAGE_UNUSED;
}
if (!in_array(self::MESSAGE_UNUSED, $states) && true === $input->getOption('only-unused') || !in_array(self::MESSAGE_MISSING, $states) && true === $input->getOption('only-missing')) {
continue;
}
$row = [$this->formatStates($states), $this->formatId($messageId), $this->sanitizeString($value)];
$table->addRow($row);
}
}
if (!$dupsOnly) {
$table->render();
//.........这里部分代码省略.........
示例9: outputQueries
/**
* Runs at the end of the command -> write resulting queries to STDOUT or a chosen output file
* @param OutputInterface $output
* @param array $queries
*/
private function outputQueries(OutputInterface $output, array $queries)
{
if (!$this->arguments['file']) {
$outFile = $this->dialog->ask($output, '<question>Where do you want to write the queries to? (file path, leave blank for stdout)</question>', $this->arguments['file']);
} else {
$outFile = $this->arguments['file'];
}
if ($outFile === null) {
$outStream = $output;
} else {
if ($this->interactive >= self::INTERACTION_HIGH) {
$append = $this->dialog->askConfirmation($output, '<question>Files will be truncated by default, do you wish to append output instead?</question>', false);
$mode = $append ? 'a' : 'w';
} else {
//default is to truncate
$mode = 'w';
}
$outStream = fopen($outFile, $mode, false);
if (!$outStream) {
$output->writeln(sprintf('<error>Failed to open file %s, falling back to stdout</error>', $outFile));
$outStream = $output;
} else {
$outStream = new StreamOutput($outStream);
}
}
$confirmKeys = [];
if ($this->interactive > self::INTERACTION_LOW) {
$confirmKeys = ['alter' => true, 'drop' => true];
}
if ($this->interactive === self::INTERACTION_EXTENDED) {
$confirmKeys['create'] = true;
$confirmKeys['constraints'] = true;
}
foreach ($queries as $section => $statements) {
$interactive = isset($confirmKeys[$section]);
if ($interactive && $this->interactive === self::INTERACTION_EXTENDED) {
$details = sprintf('<question>Do you wish to skip all %d queries for section %s (default false)</question>', count($statements), $section);
$skip = $this->dialog->askConfirmation($output, $details, false);
if ($skip) {
//skip section
continue;
}
}
$outStream->writeln(sprintf('-- %s queries', $section));
foreach ($statements as $q) {
$this->writeQueryString($outStream, $output, $q, $interactive);
}
$outStream->writeln(sprintf('-- END %s queries ' . PHP_EOL, $section));
}
}
示例10: runCommand
/**
* @param Process $process
*
* @return bool
* @throws TaskRuntimeException
* @throws \Bldr\Exception\BldrException
* @throws \Bldr\Exception\ParameterNotFoundException
* @throws \Bldr\Exception\RequiredParameterException
*/
private function runCommand(Process $process)
{
$output = $this->output;
/** @type DebugFormatterHelper $debugFormatter */
$debugFormatter = $this->getHelperSet()->get('debug_formatter');
if (null !== ($dispatcher = $this->getEventDispatcher())) {
$event = new PreExecuteEvent($this, $process);
$dispatcher->dispatch(Event::PRE_EXECUTE, $event);
if ($event->isPropagationStopped()) {
$output->writeln(['', sprintf(' <info>[%s]</info> - <comment>Stopped</comment>', $this->getName()), '']);
return true;
}
}
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE || $this->getParameter('dry_run')) {
$output->writeln(' // ' . $process->getCommandLine());
}
if ($this->getParameter('dry_run')) {
return true;
}
if ($this->hasParameter('cwd')) {
$process->setWorkingDirectory($this->getParameter('cwd'));
}
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERY_VERBOSE) {
$output->writeln(sprintf(' // Setting timeout for %d seconds.', $this->getParameter('timeout')));
}
$process->setTimeout($this->getParameter('timeout') !== 0 ? $this->getParameter('timeout') : null);
if ($this->hasParameter('output')) {
$append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
$stream = fopen($this->getParameter('output'), $append);
$output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
}
$output->writeln($debugFormatter->start(spl_object_hash($process), $process->getCommandLine()));
$process->start();
return $process;
}