本文整理汇总了PHP中Symfony\Component\Console\Application::renderException方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::renderException方法的具体用法?PHP Application::renderException怎么用?PHP Application::renderException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Application
的用法示例。
在下文中一共展示了Application::renderException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderException
/**
* Renders a caught exception.
*
* @param \Exception $e An exception instance
* @param OutputInterface $output An OutputInterface instance
*/
public function renderException($e, $output = null)
{
if (!$output) {
$output = $this->output;
if ($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
}
}
return parent::renderException($e, $output);
}
示例2: searchInPackageNames
/**
* Search for dependencies in multiple packages.
*
* @param string[] $packageNames The package names.
* @param ComposerRepository $repository The repository.
*
* @return void
*/
private function searchInPackageNames($packageNames, ComposerRepository $repository)
{
foreach ($packageNames as $packageName) {
try {
$packages = $repository->findPackages($packageName);
$this->searchInPackages($packages);
} catch (\Exception $e) {
$this->application->renderException($e, $this->output);
}
}
}
示例3: renderException
/**
* Passes exception to error handler before rendering to output
*
* @param Exception $e
* @param OutputInterface $output
* @return void
*/
public function renderException(Exception $e, OutputInterface $output)
{
if ($this->container->has('error_handler')) {
/** @var \Whoops\RunInterface $run */
$run = $this->container->get('error_handler');
// from now on ConsoleApplication will render exception
$run->allowQuit(false);
$run->writeToOutput(false);
// Ignore the return string, parent call will render exception
$run->handleException($e);
}
parent::renderException($e, $output);
}
示例4: renderException
/**
* {@inheritdoc}
*/
public function renderException(\Exception $e, OutputInterface $output)
{
$memory = fopen('php://memory', 'rw');
$errorStream = new StreamOutput($memory, OutputInterface::VERBOSITY_VERY_VERBOSE, $output ? $output->isDecorated() : null, $output ? $output->getFormatter() : null);
parent::renderException($e, $errorStream);
rewind($memory);
$exception = '';
while (!feof($memory)) {
$exception .= fread($memory, 8192);
}
fclose($memory);
$console = new ConsoleOutput();
$explode = explode("\n", rtrim($exception));
foreach ($explode as &$line) {
$line = $console->prefixWithTimestamp($line);
}
$output->write(implode("\n", $explode) . "\n");
}
示例5: command
/**
* Execute console command using it's name.
*
* @param string $command
* @param array|InputInterface $parameters
* @param OutputInterface $output
* @return CommandOutput
* @throws ConsoleException
*/
public function command($command, $parameters = [], OutputInterface $output = null)
{
$input = is_object($parameters) ? $parameters : new ArrayInput(compact('command') + $parameters);
$output = !empty($output) ? $output : new BufferedOutput();
$outerOutput = $this->container->replace(OutputInterface::class, $output);
$outerInput = $this->container->replace(InputInterface::class, $input);
//Go
$code = self::CODE_UNDEFINED;
try {
$code = $this->application()->find($command)->run($input, $output);
} catch (\Exception $exception) {
$this->application->renderException($exception, $output);
} finally {
$this->container->restore($outerInput);
$this->container->restore($outerOutput);
}
return new CommandOutput($code, $output);
}
示例6: register
/**
* Set the handlers.
*
* @param bool $debug
*/
public static function register($debug = true)
{
$errorLevels = error_reporting();
if ($debug) {
$errorLevels |= E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED;
Debug\DebugClassLoader::enable();
}
if (PHP_SAPI !== 'cli') {
Debug\ErrorHandler::register()->throwAt($errorLevels, true);
Debug\ExceptionHandler::register($debug);
} else {
$consoleHandler = function (\Exception $e) {
$app = new Application('Bolt CLI', Version::VERSION);
$output = new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG);
$app->renderException($e, $output);
ob_clean();
};
Debug\ExceptionHandler::register($debug)->setHandler($consoleHandler);
}
}
示例7: command
/**
* Execute console command using it's name.
*
* @param string $command
* @param array|InputInterface $input
* @param OutputInterface $output
* @return CommandOutput
* @throws ConsoleException
*/
public function command($command, $input = [], OutputInterface $output = null)
{
if (is_array($input)) {
$input = new ArrayInput(compact('command') + $input);
}
if (empty($output)) {
$output = new BufferedOutput();
}
//todo: do we need input scope?
$this->openScope($input, $output);
$code = self::CODE_UNDEFINED;
try {
/**
* Debug: this method creates scope for [[InputInterface]] and [[OutputInterface]].
*/
$code = $this->application()->find($command)->run($input, $output);
} catch (\Exception $exception) {
$this->application->renderException($exception, $output);
} finally {
$this->restoreScope();
}
return new CommandOutput($code, $output);
}
示例8: renderException
/**
* {@inheritDoc}
*/
public function renderException($exception, $output)
{
$io = $this->getIO();
try {
$composer = $this->getComposer(false, true);
if ($composer) {
$config = $composer->getConfig();
$minSpaceFree = 1024 * 1024;
if (($df = @disk_free_space($dir = $config->get('home'))) !== false && $df < $minSpaceFree || ($df = @disk_free_space($dir = $config->get('vendor-dir'))) !== false && $df < $minSpaceFree || ($df = @disk_free_space($dir = sys_get_temp_dir())) !== false && $df < $minSpaceFree) {
$io->writeError('<error>The disk hosting ' . $dir . ' is full, this may be the cause of the following exception</error>');
}
}
} catch (\Exception $e) {
}
if (defined('PHP_WINDOWS_VERSION_BUILD') && false !== strpos($exception->getMessage(), 'The system cannot find the path specified')) {
$io->writeError('<error>The following exception may be caused by a stale entry in your cmd.exe AutoRun</error>');
$io->writeError('<error>Check https://getcomposer.org/doc/articles/troubleshooting.md#-the-system-cannot-find-the-path-specified-windows- for details</error>');
}
if (false !== strpos($exception->getMessage(), 'fork failed - Cannot allocate memory')) {
$io->writeError('<error>The following exception is caused by a lack of memory and not having swap configured</error>');
$io->writeError('<error>Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details</error>');
}
if ($output instanceof ConsoleOutputInterface) {
parent::renderException($exception, $output->getErrorOutput());
} else {
parent::renderException($exception, $output);
}
}
示例9: renderException
/**
* {@inheritDoc}
*/
public function renderException($exception, $output)
{
if ($output instanceof ConsoleOutputInterface) {
parent::renderException($exception, $output->getErrorOutput());
} else {
parent::renderException($exception, $output);
}
}
示例10: renderException
/**
* Render the given exception.
*
* @param \Exception $e
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return void
*/
public function renderException($e, $output)
{
// If we have an exception handler instance, we will call that first in case
// it has some handlers that need to be run first. We will pass "true" as
// the second parameter to indicate that it's handling a console error.
if (isset($this->exceptionHandler)) {
$this->exceptionHandler->handleConsole($e);
}
parent::renderException($e, $output);
}
示例11: Application
<?php
date_default_timezone_set('Europe/Paris');
require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . "autoload.php";
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputDefinition;
use Evaneos\Flickr\Api\Command\ImportDirectoryCommand;
$console = new Application('Evaneos CLI', 'v0.1');
$console->setCatchExceptions(false);
$input = new ArgvInput();
$output = new ConsoleOutput();
try {
$commands = array(new ImportDirectoryCommand('flickr:import'));
foreach ($commands as $command) {
$console->add($command);
}
$result = $console->run($input, $output);
} catch (Exception $e) {
$console->renderException($e, $output);
$output->writeln('<error>' . $e->getTraceAsString() . '</error>');
exit($e->getCode());
}
return $result;
示例12: renderException
/**
* {@inheritDoc}
*/
public function renderException($exception, $output)
{
try {
$composer = $this->getComposer(false);
if ($composer) {
$config = $composer->getConfig();
$minSpaceFree = 1024 * 1024;
if (($df = @disk_free_space($dir = $config->get('home'))) !== false && $df < $minSpaceFree || ($df = @disk_free_space($dir = $config->get('vendor-dir'))) !== false && $df < $minSpaceFree) {
$output->writeln('<error>The disk hosting ' . $dir . ' is full, this may be the cause of the following exception</error>');
}
}
} catch (\Exception $e) {
}
return parent::renderException($exception, $output);
}
示例13: renderException
public function renderException($e, $output)
{
parent::renderException($e, $output);
//$this->container->get('ui.shell')->installReadlineCallback();
$this->container->setParameter('application.exit_code', ResultEvent::ERROR);
}
示例14: renderException
/**
* {@inheritdoc}
*/
public function renderException($e, $output)
{
$this->runningCommand = null;
parent::renderException($e, $output);
}
示例15: renderException
/**
* Renders a caught exception.
* @param $e
*/
public function renderException($e)
{
$this->console->renderException($e, new ConsoleOutput());
die;
}