本文整理匯總了PHP中Symfony\Component\Console\Output\OutputInterface類的典型用法代碼示例。如果您正苦於以下問題:PHP OutputInterface類的具體用法?PHP OutputInterface怎麽用?PHP OutputInterface使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了OutputInterface類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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);
}
示例2: 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);
}
}
示例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)
{
$elasticaClient = new \Elastica\Client();
$elasticaIndex = $elasticaClient->getIndex('evrika');
$elasticaIndex->create(array('number_of_shards' => 2, 'number_of_replicas' => 0, 'analysis' => array('analyzer' => array('indexAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('lowercase', 'mySnowball')), 'searchAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('standard', 'lowercase', 'mySnowball'))), 'filter' => array('mySnowball' => array('type' => 'snowball', 'language' => 'Russian')))), true);
$output->writeln('+++ evrika:elastic_index created!');
}
示例5: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$realCacheDir = $this->getContainer()->getParameter('kernel.cache_dir');
$oldCacheDir = $realCacheDir . '_old';
$filesystem = $this->getContainer()->get('filesystem');
if (!is_writable($realCacheDir)) {
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
}
if ($filesystem->exists($oldCacheDir)) {
$filesystem->remove($oldCacheDir);
}
$kernel = $this->getContainer()->get('kernel');
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
$this->getContainer()->get('cache_clearer')->clear($realCacheDir);
if ($input->getOption('no-warmup')) {
$filesystem->rename($realCacheDir, $oldCacheDir);
} else {
// the warmup cache dir name must have the same length than the real one
// to avoid the many problems in serialized resources files
$warmupDir = substr($realCacheDir, 0, -1) . '_';
if ($filesystem->exists($warmupDir)) {
$filesystem->remove($warmupDir);
}
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
$filesystem->rename($realCacheDir, $oldCacheDir);
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
sleep(1);
// workaround for windows php rename bug
}
$filesystem->rename($warmupDir, $realCacheDir);
}
$filesystem->remove($oldCacheDir);
}
示例6: 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>');
}
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $stdout)
{
// capture error output
$stderr = $stdout instanceof ConsoleOutputInterface ? $stdout->getErrorOutput() : $stdout;
if ($input->getOption('watch')) {
$stderr->writeln('<error>The --watch option is deprecated. Please use the ' . 'assetic:watch command instead.</error>');
// build assetic:watch arguments
$arguments = array('command' => 'assetic:watch', 'write_to' => $this->basePath, '--period' => $input->getOption('period'), '--env' => $input->getOption('env'));
if ($input->getOption('no-debug')) {
$arguments['--no-debug'] = true;
}
if ($input->getOption('force')) {
$arguments['--force'] = true;
}
$command = $this->getApplication()->find('assetic:watch');
return $command->run(new ArrayInput($arguments), $stdout);
}
// print the header
$stdout->writeln(sprintf('Dumping all <comment>%s</comment> assets.', $input->getOption('env')));
$stdout->writeln(sprintf('Debug mode is <comment>%s</comment>.', $this->am->isDebug() ? 'on' : 'off'));
$stdout->writeln('');
if ($this->spork) {
$batch = $this->spork->createBatchJob($this->am->getNames(), new ChunkStrategy($input->getOption('forks')));
$self = $this;
$batch->execute(function ($name) use($self, $stdout) {
$self->dumpAsset($name, $stdout);
});
} else {
foreach ($this->am->getNames() as $name) {
$this->dumpAsset($name, $stdout);
}
}
}
示例8: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$class_name = ltrim($input->getArgument('class_name'), '\\');
$namespace_root = $input->getArgument('namespace_root_path');
$match = [];
preg_match('/([a-zA-Z0-9_]+\\\\[a-zA-Z0-9_]+)\\\\(.+)/', $class_name, $match);
if ($match) {
$root_namespace = $match[1];
$rest_fqcn = $match[2];
$proxy_filename = $namespace_root . '/ProxyClass/' . str_replace('\\', '/', $rest_fqcn) . '.php';
$proxy_class_name = $root_namespace . '\\ProxyClass\\' . $rest_fqcn;
$proxy_class_string = $this->proxyBuilder->build($class_name);
$file_string = <<<EOF
<?php
// @codingStandardsIgnoreFile
/**
* This file was generated via php core/scripts/generate-proxy-class.php '{$class_name}' "{$namespace_root}".
*/
{{ proxy_class_string }}
EOF;
$file_string = str_replace(['{{ proxy_class_name }}', '{{ proxy_class_string }}'], [$proxy_class_name, $proxy_class_string], $file_string);
mkdir(dirname($proxy_filename), 0775, TRUE);
file_put_contents($proxy_filename, $file_string);
$output->writeln(sprintf('Proxy of class %s written to %s', $class_name, $proxy_filename));
}
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$newStatus = $input->getArgument('status');
$em = $this->getContainer()->get('Doctrine')->getManager();
$entity = $em->getRepository('ParkBundle:Computer')->findAll();
if ($newStatus == "actif") {
foreach ($entity as $computer) {
$computer->setEnabled(true);
}
$em->flush();
$text = "Tous les ordinateurs ont ete actives";
} elseif ($newStatus == "inactif") {
foreach ($entity as $computer) {
$computer->setEnabled(false);
}
$em->flush();
$text = "Tous les ordinateurs ont ete desactives";
} elseif ($newStatus == "toggle") {
foreach ($entity as $computer) {
$computer->setEnabled(!$computer->getEnabled());
}
$em->flush();
$text = "Tous les ordinateurs ont change d'etat";
} else {
$text = "Probleme lors de l'execution de la commande (le statut doit etre actif ou inactif)";
}
$output->writeln($text);
}
示例10: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return void
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$kernel = $this->container->get('kernel');
$router = $this->container->get('router');
$route = $input->getOption('route');
$uri = $input->getOption('uri');
$uri = $route ? $router->generate($route) : $uri;
$parameters = $input->getOption('parameters');
$parameters = json_decode($parameters, JSON_OBJECT_AS_ARRAY);
$cookies = $input->getOption('cookies');
$cookies = json_decode($cookies, JSON_OBJECT_AS_ARRAY);
$files = $input->getOption('files');
$files = json_decode($files, JSON_OBJECT_AS_ARRAY);
$server = $input->getOption('server');
$server = json_decode($server, JSON_OBJECT_AS_ARRAY);
$encoding = $input->getOption('encoding');
$content = $input->getOption('content');
$content = $this->decode($content, $encoding);
$method = $input->getOption('method') ?: 'GET';
$method = ($method === 'GET' and $content) ? 'POST' : $method;
$request = Request::create($uri, $method, $parameters, $cookies, $files, $server, $content);
$response = $kernel->handle($request, Kernel::SUB_REQUEST);
$result = $response->getContent();
if ($response->headers->get('Content-Type') === 'application/json') {
$result = json_decode($result, JSON_OBJECT_AS_ARRAY);
$result = json_encode($result, JSON_PRETTY_PRINT);
}
$output->writeln($result);
return;
}
示例11: 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);
}
示例12: 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);
}
}
示例13: 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>');
}
示例14: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$command = $input->getArgument('cmd');
$params = json_decode($input->getArgument('params'), true);
// Create new job
/** @var JobFactory $jobFactory */
$jobFactory = $this->getContainer()->get('syrup.job_factory');
$jobFactory->setStorageApiClient($this->storageApi);
$job = $jobFactory->create($command, $params);
// Add job to Elasticsearch
/** @var JobMapper $jobMapper */
$jobMapper = $this->getContainer()->get('syrup.elasticsearch.current_component_job_mapper');
$jobId = $jobMapper->create($job);
$output->writeln('Created job id ' . $jobId);
// Run Job
if ($input->getOption('run')) {
$runJobCommand = $this->getApplication()->find('syrup:run-job');
$returnCode = $runJobCommand->run(new ArrayInput(['command' => 'syrup:run-job', 'jobId' => $jobId]), $output);
if ($returnCode == 0) {
$output->writeln('Job successfully executed');
} elseif ($returnCode == 2 || $returnCode == 64) {
$output->writeln('DB is locked. Run job later using syrup:run-job');
} else {
$output->writeln('Error occured');
}
}
return 0;
}
示例15: execute
/**
* {@inheritdoc }
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$privateKeyPath = $input->getOption('privateKey');
$keyBundlePath = $input->getOption('certificate');
$path = $input->getOption('path');
if (is_null($privateKeyPath) || is_null($keyBundlePath) || is_null($path)) {
$output->writeln('--privateKey, --certificate and --path are required.');
return null;
}
$privateKey = $this->fileAccessHelper->file_get_contents($privateKeyPath);
$keyBundle = $this->fileAccessHelper->file_get_contents($keyBundlePath);
if ($privateKey === false) {
$output->writeln(sprintf('Private key "%s" does not exists.', $privateKeyPath));
return null;
}
if ($keyBundle === false) {
$output->writeln(sprintf('Certificate "%s" does not exists.', $keyBundlePath));
return null;
}
$rsa = new RSA();
$rsa->loadKey($privateKey);
$x509 = new X509();
$x509->loadX509($keyBundle);
$x509->setPrivateKey($rsa);
$this->checker->writeCoreSignature($x509, $rsa, $path);
$output->writeln('Successfully signed "core"');
}