本文整理匯總了PHP中Symfony\Component\Console\Output\OutputInterface::write方法的典型用法代碼示例。如果您正苦於以下問題:PHP OutputInterface::write方法的具體用法?PHP OutputInterface::write怎麽用?PHP OutputInterface::write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Console\Output\OutputInterface
的用法示例。
在下文中一共展示了OutputInterface::write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: importProjects
/**
* Import Projects
*/
private function importProjects()
{
$this->output->write(sprintf('%-30s', 'Importing projects'));
$previewProjects = $this->previewService->getProjects();
$created = 0;
$updated = 0;
foreach ($previewProjects as $previewProject) {
/**
* @var Project $project
*/
$project = $this->entityManager->getRepository('ProjectPreviewProjectBundle:Project')->find($previewProject->id);
if (is_null($project)) {
$project = new Project();
$project->setId($previewProject->id);
$created++;
} else {
$updated++;
}
$project->setName($previewProject->name);
$project->setArchived($previewProject->archived);
$this->entityManager->persist($project);
}
$this->output->writeln(sprintf('done (total: % 4d, created: % 4d, updated: % 4d)', $created + $updated, $created, $updated));
$this->entityManager->flush();
}
示例2: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$dm = $this->getHelper('documentManager')->getDocumentManager();
$metadatas = $dm->getMetadataFactory()->getAllMetadata();
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
// Process destination directory
if (($destPath = $input->getArgument('dest-path')) === null) {
$destPath = $dm->getConfiguration()->getProxyDir();
}
if (!is_dir($destPath)) {
mkdir($destPath, 0775, true);
}
$destPath = realpath($destPath);
if (!file_exists($destPath)) {
throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $destPath));
} elseif (!is_writable($destPath)) {
throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath));
}
if (count($metadatas)) {
foreach ($metadatas as $metadata) {
$output->write(sprintf('Processing document "<info>%s</info>"', $metadata->name) . PHP_EOL);
}
// Generating Proxies
$dm->getProxyFactory()->generateProxyClasses($metadatas, $destPath);
// Outputting information message
$output->write(PHP_EOL . sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
} else {
$output->write('No Metadata Classes to process.' . PHP_EOL);
}
}
示例3: cleanupTerms
private function cleanupTerms(Treatment $treatment)
{
// find terms for this treatment
$qb = $this->om->createQueryBuilder();
$qb->select('t2')->from('TermBundle:Term', 't2')->innerJoin('t2.termDocuments', 'td', Join::WITH, 'td.type = :treatmentType')->setParameter('treatmentType', TermDocument::TYPE_TREATMENT)->where('td.documentId = :treatmentId')->setParameter('treatmentId', $treatment->getId());
$terms = $qb->getQuery()->getResult();
$this->output->writeln('Cleaning terms for treatment #' . $treatment->getId() . ' [' . $treatment->getName() . ']');
if (\count($terms)) {
$hasInternal = false;
foreach ($terms as $term) {
$this->output->write($this->indent() . $term->getName() . " [#{$term->getId()}]" . $this->indent());
if (!$term->getInternal()) {
// if this has not been flagged as internal yet, flag it
$term->setInternal(\strtolower($term->getName()) == \strtolower($treatment->getName()));
}
if (!$hasInternal) {
$hasInternal = $term->getInternal();
}
$this->om->persist($term);
$this->output->writeln('[OK]');
}
if (!$hasInternal) {
$term = $this->createTermFromTreatment($treatment);
$this->om->persist($term);
$this->output->writeln($this->indent() . 'Added internal term');
}
} else {
$this->output->write($this->indent() . "Found no terms: ");
$term = $this->createTermFromTreatment($treatment);
$this->om->persist($term);
$this->output->writeln('[OK]');
}
}
示例4: displayResults
/**
* Displays a security report as plain text.
*
* @param OutputInterface $output
* @param string $lockFilePath The file path to the checked lock file
* @param array $vulnerabilities An array of vulnerabilities
*/
public function displayResults(OutputInterface $output, $lockFilePath, array $vulnerabilities)
{
$output->writeln("\n<fg=blue>Security Check Report\n~~~~~~~~~~~~~~~~~~~~~</>\n");
$output->writeln(sprintf('Checked file: <comment>%s</>', realpath($lockFilePath)));
$output->write("\n");
if ($count = count($vulnerabilities)) {
$status = 'CRITICAL';
$style = 'error';
} else {
$status = 'OK';
$style = 'bg=green;fg=white';
}
$output->writeln($this->formatter->formatBlock(array('[' . $status . ']', $count . ' packages have known vulnerabilities'), $style, true));
$output->write("\n");
if (0 !== $count) {
foreach ($vulnerabilities as $dependency => $issues) {
$dependencyFullName = $dependency . ' (' . $issues['version'] . ')';
$output->writeln('<info>' . $dependencyFullName . "\n" . str_repeat('-', strlen($dependencyFullName)) . "</>\n");
foreach ($issues['advisories'] as $issue => $details) {
$output->write(' * ');
if ($details['cve']) {
$output->write('<comment>' . $details['cve'] . ': </comment>');
}
$output->writeln($details['title']);
if ('' !== $details['link']) {
$output->writeln(' ' . $details['link']);
}
$output->writeln('');
}
}
}
$output->writeln("<bg=yellow;fg=white> </> This checker can only detect vulnerabilities that are referenced");
$output->writeln("<bg=yellow;fg=white> Disclaimer </> in the SensioLabs security advisories database. Execute this");
$output->writeln("<bg=yellow;fg=white> </> command regularly to check the newly discovered vulnerabilities.\n");
}
示例5: execute
/**
* Executes installation
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return null|integer null or 0 if everything went fine, or an error code
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$output->write("Creating Branch logo directory..." . "\n");
$this->createBranchLogoDirectory();
$output->writeln("Done" . "\n");
$output->write("Creating attachments directory..." . "\n");
$this->createAttachmentsDirectory();
$output->writeln("Done" . "\n");
$output->write("Installing DB schema..." . "\n");
$this->updateDbSchema();
$output->writeln("Done" . "\n");
$this->loadData($output);
$this->updateEntityConfig($output);
$output->write("Updating navigation..." . "\n");
$this->updateNavigation($output);
$output->writeln("Done" . "\n");
$output->write("Loading migration data" . "\n");
$this->loadDataFixtures($output);
$output->writeln("Done" . "\n");
} catch (\Exception $e) {
$output->writeln($e->getMessage());
return 255;
}
$output->writeln("Installed!" . "\n");
return 0;
}
示例6: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var ResourceHelper $helper */
$helper = $this->getHelper('resource');
$ryzomDataPath = $input->getOption('ryzom');
if (empty($ryzomDataPath) || !file_exists($ryzomDataPath . '/gamedev.bnp') || !file_exists($ryzomDataPath . '/lmconts.packed') || !file_exists($ryzomDataPath . '/world.packed_sheets')) {
throw new \InvalidArgumentException("Invalid Ryzom data path. gamedev.bnp, lmconts.packed or world.packed_sheets not found");
}
$psLoader = new PackedSheetsLoader($ryzomDataPath);
// labels.json
$output->write('<info>building labels.json</info>...');
/** @var TranslateHelper $translator */
$translator = $this->getHelper('translator');
/** @var StringsManager $sm */
$sm = $translator->load($ryzomDataPath);
$lmconts = $psLoader->load('lmconts');
$continents = $lmconts->get('continents');
$this->buildLabels($continents, $sm, $helper->get('labels.json.file'));
$output->writeln('');
// server.json
$output->write('<info>building server.json</info>...');
$ps = $psLoader->load('world');
// 6 == sheetid for 'ryzom.world'
$world = $ps->get(6);
if (!$world) {
throw new \RuntimeException("Failed to load world.packed_sheets");
}
$this->buildServerZones($world, $helper->get('server.json.file'));
$output->writeln('');
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$only_chekc = $input->getOption('only-check');
if (file_exists('composer.phar')) {
if ($only_chekc) {
$output->writeln('<info>Composer installed</info>');
return 0;
}
$output->write('Composer already installed, upgrading it...');
exec('php composer.phar selfupdate', $res, $ret);
if ($ret == 0) {
$output->writeln('<info>DONE</info>');
} else {
$output->writeln('<error>ERROR</error>');
return 1;
}
} else {
if ($only_chekc) {
$output->writeln('<error>Composer not installed</error>');
return 1;
}
$output->write('Installing composer...');
exec('php -r "readfile(\'https://getcomposer.org/installer\');" | php', $res, $ret);
if ($ret == 0) {
$output->writeln('<info>DONE</info>');
return 0;
} else {
$output->writeln('<error>ERROR - please install composer manually (https://getcomposer.org/download/)</error>');
return 1;
}
}
}
示例8: flush
/** flush printer buffer */
public function flush()
{
fseek($this->stream, 0);
$this->output->write(stream_get_contents($this->stream));
fclose($this->stream);
$this->initStream();
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$fileInfo = new \SplFileInfo($this->getContainer()->getParameter('kernel.root_dir') . '/../web/sitemap.xml');
if ($fileInfo->isFile() && $fileInfo->isReadable()) {
$output->write('Reading sitemap.xml...');
$file = $fileInfo->openFile();
$xml = '';
while (!$file->eof()) {
$xml .= $file->fgets();
}
$output->writeln(' done.');
$output->write('Updating sitemap.xml...');
$sitemap = new \SimpleXMLIterator($xml);
$sitemap->rewind();
$lastmodDate = new \DateTime();
$lastmodDate->sub(new \DateInterval('P1D'));
$lastmodDateFormatted = $lastmodDate->format('Y-m-d');
while ($sitemap->valid()) {
$sitemap->current()->lastmod = $lastmodDateFormatted;
$sitemap->next();
}
$file = $file->openFile('w');
$file->fwrite($sitemap->asXML());
$output->writeln(' done.');
} else {
$output->writeln('Error: Cannot open file web/sitemap.xml');
}
}
示例10: displayResults
/**
* Displays a security report as simple plain text.
*
* @param OutputInterface $output
* @param string $lockFilePath The file path to the checked lock file
* @param array $vulnerabilities An array of vulnerabilities
*/
public function displayResults(OutputInterface $output, $lockFilePath, array $vulnerabilities)
{
$output->writeln(sprintf('Security Check Report: <comment>%s</>', realpath($lockFilePath)));
if ($count = count($vulnerabilities)) {
$status = 'CRITICAL';
$style = 'error';
} else {
$status = 'OK';
$style = 'info';
}
$output->writeln(sprintf('<%s>[%s] %d %s known vulnerabilities</>', $style, $status, $count, 1 === $count ? 'package has' : 'packages have'));
if (0 !== $count) {
$output->write("\n");
foreach ($vulnerabilities as $dependency => $issues) {
$dependencyFullName = $dependency . ' (' . $issues['version'] . ')';
$output->writeln('<info>' . $dependencyFullName . "\n" . str_repeat('-', strlen($dependencyFullName)) . "</>\n");
foreach ($issues['advisories'] as $issue => $details) {
$output->write(' * ');
if ($details['cve']) {
$output->write('<comment>' . $details['cve'] . ': </comment>');
}
$output->writeln($details['title']);
if ('' !== $details['link']) {
$output->writeln(' ' . $details['link']);
}
$output->writeln('');
}
}
}
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$notFound = false;
$source = $input->getArgument('source');
$outputPath = $input->getArgument('output');
$worker = new \MySQLExtractor\Application();
$scanPathname = realpath($source);
preg_match('/(.*):(.*)@(.*)\\/(.*)/', $source, $serverDetails);
if (is_array($serverDetails) && count($serverDetails) === 5) {
$mysqlCredentials = new \stdClass();
$mysqlCredentials->dbuser = $serverDetails[1];
$mysqlCredentials->dbpass = $serverDetails[2];
$mysqlCredentials->host = $serverDetails[3];
$mysqlCredentials->dbname = $serverDetails[4];
$worker->processServer($mysqlCredentials);
} else {
if ($scanPathname) {
$worker->processDisk($scanPathname);
} else {
// error, path not found
$notFound = true;
}
}
if ($notFound) {
$output->write('Error: invalid source format, check if the source path exists and the format is valid.');
} else {
$worker->output($outputPath, $results = $worker->getDatabases());
// will output .json files for each database
$output->write('Finished. Check the output folder.' . PHP_EOL . implode(PHP_EOL, $worker->statistics()) . PHP_EOL);
}
}
示例12: execute
/**
* @SuppressWarnings(PHPMD.ExitExpression)
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*/
protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output)
{
$entityManager = $this->getHelper('em')->getEntityManager();
$users = $entityManager->getRepository('\\Jazzee\\Entity\\User')->findAll();
if (!$users) {
$output->write('<error>There are no users in the system. User add-user to create one.</error>' . PHP_EOL);
exit;
}
$find = array('name' => $input->getArgument('role name'));
if ($input->getOption('global-only')) {
$find['isGlobal'] = true;
}
$roles = $entityManager->getRepository('\\Jazzee\\Entity\\Role')->findBy($find);
if (count($roles) == 0) {
$output->write('<error>There are no roles with that name.</error>' . PHP_EOL);
exit;
}
if (!$input->getOption('multiple') and count($roles) > 1) {
$output->write('<error>There are ' . count($roles) . ' roles with that name. In order to add users to muliple roles you must use the --multiple option.</error>' . PHP_EOL);
exit;
}
$results = array();
foreach ($entityManager->getRepository('\\Jazzee\\Entity\\User')->findBy(array(), array('lastName' => 'ASC', 'firstName' => 'ASC')) as $user) {
foreach ($roles as $role) {
if (!$user->hasRole($role)) {
$user->addRole($role);
$results[] = "<info>{$user->getLastName()}, {$user->getFirstName()} added to {$role->getName()} role</info>";
}
}
$entityManager->persist($user);
}
$entityManager->flush();
$output->write(implode(PHP_EOL, $results) . PHP_EOL . '<info>Total of ' . count($results) . ' changes</info>' . PHP_EOL);
}
示例13: execute
public function execute(MinimumStrictCoverage $minimumStrictCoverage, $errorMessage)
{
$outputMessage = new PreCommitOutputWriter(self::EXECUTE_MESSAGE);
$this->output->write($outputMessage->getMessage());
$this->strictCoverageTool->run($minimumStrictCoverage, $errorMessage);
$this->output->writeln($outputMessage->getSuccessfulMessage());
}
示例14: execute
/**
* Parses the clover XML file and spits out coverage results to the console.
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
public function execute(InputInterface $input, OutputInterface $output)
{
// Get options
$project = $input->getOption('project');
if ($input->getOption('file')) {
$file = $input->getOption('file');
} else {
$file = '';
}
// First step : Analysing config
$config_path = $input->getArgument('config');
$guardian = new Guardian($config_path);
$output->writeln(sprintf('Analysing config file : <info>%s</info>', $config_path));
$output->write("\n");
$output->writeln(sprintf('> Start SQL restore : <info>%s</info>', $project));
$output->writeln('------------------------------');
try {
$guardian->restoreDatabase($project, $file);
} catch (\Exception $e) {
if ($e->getCode() == 0) {
$style = 'error';
} else {
$style = 'comment';
}
$output->write(sprintf(' : <' . $style . '>%s</' . $style . '>', $e->getMessage()));
}
$output->write("\n");
$output->writeln('Finished : <info>Done</info>');
}
示例15: install
private function install(OutputInterface $output, $targetFolder, $symlinkName, $forceDownload, HttpSource $source)
{
$version = $source->getVersion();
$extractedFolder = 'PhpStorm-' . $version;
if (is_dir($targetFolder . '/' . $extractedFolder) && false === $forceDownload) {
$output->writeln(sprintf('<comment>Phpstorm <info>%s</info> already exists, skipping download..</comment>', $version));
} else {
$output->write(sprintf('<comment>Download %s </comment><info>%s</info><comment>...</comment>', $source->getName(), $version));
$downloadProcess = new Process(sprintf("wget %s -O phpstorm.tar.gz", escapeshellarg($source->getUrl())));
$downloadProcess->setTimeout(3600);
$downloadProcess->run();
$output->writeln(' <info>OK</info>');
if (!$downloadProcess->isSuccessful()) {
throw new \RuntimeException($downloadProcess->getErrorOutput());
}
$output->write('<comment>Extracting...</comment>');
$extractProcess = new Process(sprintf('tar xfz phpstorm.tar.gz; rm phpstorm.tar.gz; mv %1$s %2$s', escapeshellarg($extractedFolder), escapeshellarg($targetFolder)));
$extractProcess->run();
$output->writeln(' <info>OK</info>');
if (!$extractProcess->isSuccessful()) {
throw new \RuntimeException($extractProcess->getErrorOutput());
}
}
$output->write('<comment>Linking...</comment>');
$command = sprintf('cd %2$s && ln -s -f -T %1$s %3$s', escapeshellarg($extractedFolder), escapeshellarg($targetFolder), escapeshellarg($symlinkName));
$linkProcess = new Process($command);
$linkProcess->run();
$output->writeln(' <info>OK</info>');
if (!$linkProcess->isSuccessful()) {
throw new \RuntimeException($linkProcess->getErrorOutput());
}
}