本文整理匯總了PHP中Symfony\Component\Console\Output\ConsoleOutput類的典型用法代碼示例。如果您正苦於以下問題:PHP ConsoleOutput類的具體用法?PHP ConsoleOutput怎麽用?PHP ConsoleOutput使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ConsoleOutput類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$rc = 0;
try {
if (!$input->getOption('force')) {
if (!$input->isInteractive()) {
throw new Exception("You have to specify the --force option in order to run this command");
}
$confirmQuestion = new ConfirmationQuestion('Are you sure you want to update this concrete5 installation?');
if (!$this->getHelper('question')->ask($input, $output, $confirmQuestion)) {
throw new Exception("Operation aborted.");
}
}
$configuration = new \Concrete\Core\Updater\Migrations\Configuration();
$output = new ConsoleOutput();
$configuration->setOutputWriter(new OutputWriter(function ($message) use($output) {
$output->writeln($message);
}));
Update::updateToCurrentVersion($configuration);
} catch (Exception $x) {
$output->writeln('<error>' . $x->getMessage() . '</error>');
$rc = 1;
}
return $rc;
}
示例2: createConsoleOutput
/**
* @return OutputWriter
*/
public static function createConsoleOutput()
{
$output = new ConsoleOutput();
return new OutputWriter(function ($message) use($output) {
$output->write($message, TRUE);
});
}
示例3: __construct
/**
* @param string $name application name
* @param string $version application version
* @SuppressWarnings(PHPMD.ExitExpression)
*/
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
{
$this->serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php')->getServiceManager();
$generationDirectoryAccess = new GenerationDirectoryAccess($this->serviceManager);
if (!$generationDirectoryAccess->check()) {
$output = new ConsoleOutput();
$output->writeln('<error>Command line user does not have read and write permissions on var/generation directory. Please' . ' address this issue before using Magento command line.</error>');
exit(0);
}
/**
* Temporary workaround until the compiler is able to clear the generation directory
* @todo remove after MAGETWO-44493 resolved
*/
if (class_exists(CompilerPreparation::class)) {
$compilerPreparation = new CompilerPreparation($this->serviceManager, new ArgvInput(), new File());
$compilerPreparation->handleCompilerEnvironment();
}
if ($version == 'UNKNOWN') {
$directoryList = new DirectoryList(BP);
$composerJsonFinder = new ComposerJsonFinder($directoryList);
$productMetadata = new ProductMetadata($composerJsonFinder);
$version = $productMetadata->getVersion();
}
parent::__construct($name, $version);
}
示例4: writeln
public function writeln($sprintf)
{
$arguments = func_get_args();
$arguments[0] .= PHP_EOL;
$message = call_user_func_array("sprintf", $arguments);
$this->laravelConsoleOutput->write($message);
}
示例5: execute_commands
/**
* @param $commands
* @param \Symfony\Component\Console\Output\ConsoleOutput $output
*
* @return boolean
*/
function execute_commands($commands, $output)
{
foreach ($commands as $command) {
list($command, $message, $allowFailure) = $command;
$output->write(sprintf(' - %\'.-70s', $message));
$return = array();
if (is_callable($command)) {
$success = $command($output);
} else {
$p = new \Symfony\Component\Process\Process($command);
$p->setTimeout(null);
$p->run(function ($type, $data) use(&$return) {
$return[] = $data;
});
$success = $p->isSuccessful();
}
if (!$success && !$allowFailure) {
$output->writeln('<error>KO</error>');
$output->writeln(sprintf('<error>Fail to run: %s</error>', is_callable($command) ? '[closure]' : $command));
foreach ($return as $data) {
$output->write($data, false, OutputInterface::OUTPUT_RAW);
}
$output->writeln("If the error is coming from the sandbox,");
$output->writeln("please report the issue to https://github.com/sonata-project/sandbox/issues");
return false;
} else {
if (!$success) {
$output->writeln("<info>!!</info>");
} else {
$output->writeln("<info>OK</info>");
}
}
}
return true;
}
示例6: run
/**
* Method overridden to add output customizations and use the output object
* for application logging.
*/
public function run(InputInterface $input = null, OutputInterface $output = null)
{
if (null === $output) {
$output = new ConsoleOutput();
$output->setFormatter(new OutputFormatter($output->isDecorated()));
}
return parent::run($input, $output);
}
示例7: checkDependencies
public function checkDependencies()
{
$output = new ConsoleOutput();
if (!extension_loaded('mbstring')) {
$output->writeln("\n<error>Missing Dependency: Please install the Multibyte String Functions.</error>\n" . "More help: http://www.php.net/manual/en/mbstring.installation.php\n", $this->outputFormat);
exit(1);
}
}
示例8: run
public function run(InputInterface $input = null, OutputInterface $output = null)
{
if (null === $output) {
$output = new ConsoleOutput();
}
$output->getFormatter()->getStyle('info')->setForeground('magenta');
$output->getFormatter()->getStyle('comment')->setForeground('cyan');
return parent::run($input, $output);
}
示例9: printMessage
private static function printMessage($s, $tag)
{
if (PHP_SAPI === 'cli') {
$output = new ConsoleOutput();
$output->writeln('<' . $tag . '>' . $s . '</' . $tag . '>');
} else {
error_log(strtoupper($tag) . ': ' . $s);
}
}
示例10: execute_commands
/**
* @param $commands
* @param \Symfony\Component\Console\Output\ConsoleOutput $output
* @return void
*/
function execute_commands($commands, $output)
{
foreach ($commands as $command) {
$output->writeln(sprintf('<info>Executing : </info> %s', $command));
$p = new \Symfony\Component\Process\Process($command);
$exit = $p->run(function ($type, $data) use($output) {
$output->write($data);
});
$output->writeln("");
}
}
示例11: setUp
protected function setUp()
{
$this->oldApplicationContext = ApplicationContext::getInstance();
$this->applicationContext = $this->createApplicationContext();
$this->applicationContext->setPlugin($this->getPlugin());
$this->applicationContext->setComponent('input', new ArgvInput());
$output = new ConsoleOutput();
$output->setDecorated(false);
$this->applicationContext->setComponent('output', $output);
ApplicationContext::setInstance($this->applicationContext);
}
示例12: register
/**
* Registers services on the given app.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param Application $app An Application instance
*/
public function register(Application $app)
{
$app['migrations.output_writer'] = new OutputWriter(function ($message) {
$output = new ConsoleOutput();
$output->writeln($message);
});
$app['migrations.directory'] = null;
$app['migrations.name'] = 'Migrations';
$app['migrations.namespace'] = null;
$app['migrations.table_name'] = 'migration_versions';
}
示例13: install
/**
* install
*
* @return void
*/
public static function install()
{
$output = new ConsoleOutput();
$style = new OutputFormatterStyle('green');
$output->getFormatter()->setStyle('green', $style);
$assets = array('resources/cache', 'resources/log', 'web/assets');
foreach ($assets as $asset) {
self::createAndChmod($asset, 0777);
$output->writeln(sprintf('<green>Generating "%s" asset dir</green>', $asset));
}
exec('php console assetic:dump');
}
示例14: testShutdownToConsoleOutput
public function testShutdownToConsoleOutput()
{
ob_start();
$out = new ConsoleOutput();
$err = new StreamOutput(fopen('php://memory', 'w', false));
$out->setErrorOutput($err);
$app = new Application('test', 'beta');
$app->configure(null, $out);
Application::shutdownFunction($app);
rewind($err->getStream());
$this->assertContains('exit()', stream_get_contents($err->getStream()));
}
示例15: load
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
/** @var KernelInterface $kernel */
$kernel = $this->container->get('kernel');
if (in_array($kernel->getEnvironment(), $this->getEnvironments())) {
$this->doLoad($manager);
} else {
$ouput = new ConsoleOutput();
$msg = '...Not for ' . $kernel->getEnvironment() . ' environment';
$ouput->writeln(' <comment>></comment> <comment>' . $msg . '</comment>');
}
}