本文整理匯總了PHP中Symfony\Component\Console\Output\OutputInterface::writeln方法的典型用法代碼示例。如果您正苦於以下問題:PHP OutputInterface::writeln方法的具體用法?PHP OutputInterface::writeln怎麽用?PHP OutputInterface::writeln使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Console\Output\OutputInterface
的用法示例。
在下文中一共展示了OutputInterface::writeln方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getArgument('path');
if (!file_exists($path)) {
$output->writeln("{$path} is not a file or a path");
}
$filePaths = [];
if (is_file($path)) {
$filePaths = [realpath($path)];
} elseif (is_dir($path)) {
$filePaths = array_diff(scandir($path), array('..', '.'));
} else {
$output->writeln("{$path} is not known.");
}
$generator = new StopwordGenerator($filePaths);
if ($input->getArgument('type') === 'json') {
echo json_encode($this->toArray($generator->getStopwords()), JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE);
echo json_last_error_msg();
die;
$output->write(json_encode($this->toArray($generator->getStopwords())));
} else {
$stopwords = $generator->getStopwords();
$stdout = fopen('php://stdout', 'w');
echo 'token,freq' . PHP_EOL;
foreach ($stopwords as $token => $freq) {
fputcsv($stdout, [utf8_encode($token), $freq]) . PHP_EOL;
}
fclose($stdout);
}
}
示例2: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$url = $input->getOption('url');
$email = $input->getOption('email');
$disable = $input->getOption('disable');
$events = $input->getOption('event');
if (!$url && !$email) {
$output->writeln('<error>Must specify either a url or an email address</error>');
return;
}
if ($url && $email) {
$output->writeln('<error>Must specify only a url or an email address</error>');
return;
}
if (!($resource = $this->getResource('webhook', $output))) {
return;
}
if ($url) {
$resource->setUrl($url);
} else {
$resource->setEmail($email);
}
$resource->setEventTypes($events ? $events : Webhook::$events);
$this->getApi()->create($resource);
$resource = $this->getApi()->getLastResponse();
$resource = $resource['body']['data'];
$table = $this->getHelperSet()->get('table');
$this->formatTableRow($resource, $table, false);
$output->writeln('<info>Webhook created</info>');
$table->render($output);
}
示例3: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$doctrine = $this->getContainer()->get('doctrine');
$em = $doctrine->getManager();
$name = $input->getArgument('name');
$system = $input->getArgument('system');
/* @var RepositoryInterface $roleRepository */
$repository = $this->getContainer()->get('sulu.repository.role');
$role = $repository->findOneByName($name);
if ($role) {
$output->writeln(sprintf('<error>Role "%s" already exists.</error>', $name));
return 1;
}
/** @var RoleInterface $role */
$role = $repository->createNew();
$role->setName($name);
$role->setSystem($system);
$pool = $this->getContainer()->get('sulu_admin.admin_pool');
$securityContexts = $pool->getSecurityContexts();
// flatten contexts
$securityContextsFlat = [];
array_walk_recursive($securityContexts['Sulu'], function ($value) use(&$securityContextsFlat) {
$securityContextsFlat[] = $value;
});
foreach ($securityContextsFlat as $securityContext) {
$permission = new Permission();
$permission->setRole($role);
$permission->setContext($securityContext);
$permission->setPermissions(127);
$role->addPermission($permission);
}
$em->persist($role);
$em->flush();
$output->writeln(sprintf('Created role "<comment>%s</comment>" in system "<comment>%s</comment>".', $role->getName(), $role->getSystem()));
}
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
// Replace this with dependency injection once available
/** @var DiagnosticService $diagnosticService */
$diagnosticService = StaticContainer::get('Piwik\\Plugins\\Diagnostics\\DiagnosticService');
$showAll = $input->getOption('all');
$report = $diagnosticService->runDiagnostics();
foreach ($report->getAllResults() as $result) {
$items = $result->getItems();
if (!$showAll && $result->getStatus() === DiagnosticResult::STATUS_OK) {
continue;
}
if (count($items) === 1) {
$output->writeln($result->getLabel() . ': ' . $this->formatItem($items[0]), OutputInterface::OUTPUT_PLAIN);
continue;
}
$output->writeln($result->getLabel() . ':');
foreach ($items as $item) {
$output->writeln("\t- " . $this->formatItem($item), OutputInterface::OUTPUT_PLAIN);
}
}
if ($report->hasWarnings()) {
$output->writeln(sprintf('<comment>%d warnings detected</comment>', $report->getWarningCount()));
}
if ($report->hasErrors()) {
$output->writeln(sprintf('<error>%d errors detected</error>', $report->getErrorCount()));
return 1;
}
return 0;
}
示例5: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$remoteFilename = 'http://get.insight.sensiolabs.com/insight.phar';
$localFilename = $_SERVER['argv'][0];
$tempFilename = basename($localFilename, '.phar') . '-temp.phar';
try {
copy($remoteFilename, $tempFilename);
if (md5_file($localFilename) == md5_file($tempFilename)) {
$output->writeln('<info>insight is already up to date.</info>');
unlink($tempFilename);
return;
}
chmod($tempFilename, 0777 & ~umask());
// test the phar validity
$phar = new \Phar($tempFilename);
// free the variable to unlock the file
unset($phar);
rename($tempFilename, $localFilename);
$output->writeln('<info>insight updated.</info>');
} catch (\Exception $e) {
if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
throw $e;
}
unlink($tempFilename);
$output->writeln('<error>The download is corrupt (' . $e->getMessage() . ').</error>');
$output->writeln('<error>Please re-run the self-update command to try again.</error>');
}
}
示例6: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$inputSource = $input->getOption('input');
$size = (int) $input->getOption('size');
if ($size < 1 || $size > 2000) {
$output->writeln('<error>Sample size must be a positive integer between 1 and 2000.</error>');
return;
}
// Input size should be 10 times the size of the sample
$streamSize = $size * 10;
switch ($inputSource) {
case 'stdin':
$stream = new StreamIterator();
break;
case 'random.org':
$stream = new RandomOrgIterator($this->httpClient);
$stream->setLength($streamSize);
break;
case 'internal':
$stream = new RandomByteIterator();
$stream->setLength($streamSize);
break;
default:
$output->writeln('<error>Unknown input source: "' . $inputSource . '". Use either stdin, random.org or internal.</error>');
return;
}
$this->sampler->setStream($stream);
$result = $this->sampler->getSampleAsString($size);
$output->writeln($result);
}
示例7: runCommand
protected function runCommand(InputInterface $input, OutputInterface $output)
{
$output->writeln('');
$executedMigrations = $this->manager->executedMigrations();
$output->writeln('<comment>Executed migrations</comment>');
if (empty($executedMigrations)) {
$output->writeln('<info>No executed migrations</info>');
} else {
$rows = [];
foreach ($executedMigrations as $migration) {
$rows[] = [ltrim($migration['classname'], '\\'), $migration['executed_at']];
}
$this->printTable(['Class name', 'Executed at'], $rows, $output);
}
$output->writeln('');
$migrations = $this->manager->findMigrationsToExecute(Manager::TYPE_UP);
$output->writeln('<comment>Migrations to execute</comment>');
if (empty($migrations)) {
$output->writeln('<info>No migrations to execute</info>');
} else {
$rows = [];
foreach ($migrations as $migration) {
$rows[] = [$migration->getClassName()];
}
$this->printTable(['Class name'], $rows, $output);
}
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$header_style = new OutputFormatterStyle('white', 'green', array('bold'));
$output->getFormatter()->setStyle('header', $header_style);
$start = intval($input->getOption('start'));
$stop = intval($input->getOption('stop'));
if ($start >= $stop || $start < 0) {
throw new \InvalidArgumentException('Stop number should be greater than start number');
}
$output->writeln('<header>Fibonacci numbers between ' . $start . ' - ' . $stop . '</header>');
$xnM2 = 0;
// set x(n-2)
$xnM1 = 1;
// set x(n-1)
$xn = 0;
// set x(n)
$totalFiboNr = 0;
while ($xnM2 <= $stop) {
if ($xnM2 >= $start) {
$output->writeln('<header>' . $xnM2 . '</header>');
$totalFiboNr++;
}
$xn = $xnM1 + $xnM2;
$xnM2 = $xnM1;
$xnM1 = $xn;
}
$output->writeln('<header>Total of Fibonacci numbers found = ' . $totalFiboNr . ' </header>');
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$subUrls = $input->getArgument('url');
$outputFile = $input->getArgument('output-file');
// Daten laden
$kosS = new KingOfSatScrapper();
$output->writeln('Start Pulling Data');
if (count($subUrls) > 0) {
$firstRun = true;
foreach ($subUrls as $url) {
$data = $kosS->getTransponderData($url);
$output->writeln(count($data) . ' Transponders found in ' . $url);
if (true === $firstRun && count($data) > 0) {
$this->setupExcel(array_keys($data[0]));
$firstRun = false;
}
$this->addRowsToExcel($data);
}
// Daten ausgeben
$output->writeln('Generate Excelfile: ' . $outputFile);
$this->saveExcel($outputFile);
} else {
$output->writeln('<error>Missing pages to Scrap. See help.</error>');
}
$output->writeln('<info>(c) Steven Buehner <buehner@me.com></info>');
}
示例10: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine')->getManager();
$scheduler = $this->getContainer()->get('scheduler');
$campaignId = $input->getArgument('campaignId');
$deliveryTime = new \DateTime($input->getArgument('deliverytime'));
$month = $input->getArgument('month');
$year = $input->getArgument('year');
$date = $input->getArgument('date');
// The date at which the job is to be run
$dateParts = explode('-', $date);
if (!checkdate($dateParts[1], $dateParts[2], $dateParts[0])) {
$output->writeLn("<error>Invalid date or format. Correct format is Y-m-d</error>");
return;
}
$now = new \DateTime();
$output->writeln("<comment>Scheduling recommendations email started on {$now->format('Y-m-d H:i:s')}</comment>");
// Get All Users
$qb = $em->createQueryBuilder();
$qb->add('select', 'DISTINCT u.id')->add('from', 'ClassCentralSiteBundle:User u')->join('u.userPreferences', 'up')->join('u.follows', 'uf')->andWhere('uf is NOT NULL')->andWhere("up.value = 1")->andWhere('u.isverified = 1')->andWhere("up.type=" . UserPreference::USER_PREFERENCE_PERSONALIZED_COURSE_RECOMMENDATIONS);
$users = $qb->getQuery()->getArrayResult();
$scheduled = 0;
$dt = new \DateTime($date);
$deliveryTime = $deliveryTime->format(\DateTime::RFC2822);
foreach ($users as $user) {
$id = $scheduler->schedule($dt, RecommendationEmailJob::RECOMMENDATION_EMAIL_JOB_TYPE, 'ClassCentral\\MOOCTrackerBundle\\Job\\RecommendationEmailJob', array('campaignId' => $campaignId, 'deliveryTime' => $deliveryTime, 'month' => $month, 'year' => $year), $user['id']);
if ($id) {
$scheduled++;
}
}
$output->writeln("<info>{$scheduled} recommendation emails jobs scheduled</info>");
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine')->getManager();
/** @var PluginManager $processManager */
$output->writeln('Updating Datamaps...');
$json = file_get_contents($input->getArgument('url') . '/datamap/list/json');
if (!$json) {
throw new \Exception('Wrong JSON response.');
}
$datamaps = json_decode($json, true);
if (count($datamaps)) {
foreach ($datamaps as $datamap) {
$output->write('Updating map "' . $datamap['name'] . '... ');
$localDatamap = $em->getRepository('VRAppBundle:Datamap')->findOneBy(['name' => $datamap['name']]);
if (!$localDatamap) {
$localDatamap = new Datamap();
$localDatamap->setName($datamap['name']);
}
$localDatamap->setType($datamap['type']);
$localDatamap->setMap(base64_decode($datamap['map']));
$localDatamap->setDescription($datamap['description']);
$em->persist($localDatamap);
$em->flush();
$output->writeln('<info>Done</info>');
}
}
$output->writeln('Finished.');
}
示例12: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$i = 0;
$kernel = $this->getContainer()->get('kernel');
$doctrine = $this->getContainer()->get('doctrine');
$entityManager = $doctrine->getEntityManager();
$cron = new Cron();
$cron->setTimestamp(time());
$cron->setAction('Observe Alarms Start');
$entityManager->persist($cron);
$entityManager->flush();
$isSandbox = $input->getOption('sandbox');
$isEmulation = $input->getOption('emulate');
$output->writeln('Sandbox: ' . $isSandbox);
$output->writeln('Emulation: ' . $isEmulation);
// operating under the assumption that this thing is executed by a cronjob, this thing needs to be run for just a minute
$intervalSpent = 0;
while ($intervalSpent <= self::CRON_INTERVAL) {
$detector = new AlarmDetector($doctrine);
$detector->detectAlarms($isEmulation);
$output->writeln(PHP_EOL . ++$i . PHP_EOL);
usleep(self::CHECK_INTERVAL);
// 250ms
$intervalSpent += self::CHECK_INTERVAL;
}
}
示例13: execute
/**
* @see Console\Command\Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$module = $input->getArgument('module');
$modules = $this->moduleManager->getModules();
$path = "{$this->modulesDir}/{$module}-module";
if (isset($modules[$module])) {
$output->writeln("<error>Module '{$module}' already exists.</error>");
return;
}
if (file_exists($path)) {
$output->writeln("<error>Path '" . $path . "' exists.</error>");
return;
}
if (!is_writable(dirname($path))) {
$output->writeln("<error>Path '" . dirname($path) . "' is not writable.</error>");
return;
}
umask(00);
mkdir($path, 0777, TRUE);
file_put_contents($path . '/Module.php', $this->getModuleFile($module));
file_put_contents($path . '/composer.json', $this->getComposerFile($module));
file_put_contents($path . '/readme.md', $this->getReadmeFile($module));
mkdir($path . '/Resources/config', 0777, TRUE);
mkdir($path . '/Resources/public', 0777, TRUE);
mkdir($path . '/Resources/translations', 0777, TRUE);
mkdir($path . '/Resources/layouts', 0777, TRUE);
mkdir($path . '/' . ucfirst($module) . 'Module', 0777, TRUE);
}
示例14: 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;
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$bundleName = $input->getArgument('bundle');
$filterEntity = $input->getOption('entity');
$foundBundle = $this->findBundle($bundleName);
if ($metadatas = $this->getBundleMetadatas($foundBundle)) {
$output->writeln(sprintf('Generating entities for "<info>%s</info>"', $foundBundle->getName()));
$entityGenerator = $this->getEntityGenerator();
foreach ($metadatas as $metadata) {
if ($filterEntity && $metadata->getReflClass()->getShortName() !== $filterEntity) {
continue;
}
if (strpos($metadata->name, $foundBundle->getNamespace()) === false) {
throw new \RuntimeException(
"Entity " . $metadata->name . " and bundle don't have a common namespace, ".
"generation failed because the target directory cannot be detected.");
}
$output->writeln(sprintf(' > generating <comment>%s</comment>', $metadata->name));
$entityGenerator->generate(array($metadata), $this->findBasePathForBundle($foundBundle));
}
} else {
throw new \RuntimeException("Bundle " . $bundleName . " does not contain any mapped entities.");
}
}