当前位置: 首页>>代码示例>>PHP>>正文


PHP ConsoleExceptionEvent::getException方法代码示例

本文整理汇总了PHP中Symfony\Component\Console\Event\ConsoleExceptionEvent::getException方法的典型用法代码示例。如果您正苦于以下问题:PHP ConsoleExceptionEvent::getException方法的具体用法?PHP ConsoleExceptionEvent::getException怎么用?PHP ConsoleExceptionEvent::getException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Console\Event\ConsoleExceptionEvent的用法示例。


在下文中一共展示了ConsoleExceptionEvent::getException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onConsoleException

 /**
  * Logs exception events for AcmePhp commands.
  *
  * @param ConsoleExceptionEvent $event
  */
 public function onConsoleException(ConsoleExceptionEvent $event)
 {
     if (!$this->isAcmePhpCommand($event->getCommand())) {
         return;
     }
     $this->logger->error('Exception thrown while running command "{command}". Message: "{message}".', ['command' => $event->getCommand()->getName(), 'message' => $event->getException()->getMessage(), 'exception' => $event->getException()]);
 }
开发者ID:acmephp,项目名称:symfony-bundle,代码行数:12,代码来源:LogCommandListener.php

示例2: onException

 /**
  * React to any console exceptions.
  *
  * @param ConsoleExceptionEvent    $event
  */
 public function onException(ConsoleExceptionEvent $event)
 {
     $exception = $event->getException();
     // Replace Guzzle connect exceptions with a friendlier message. This
     // also prevents the user from seeing two exceptions (one direct from
     // Guzzle, one from RingPHP).
     if ($exception instanceof ConnectException && strpos($exception->getMessage(), 'cURL error 6') !== false) {
         $request = $exception->getRequest();
         $event->setException(new ConnectionFailedException("Failed to connect to host: " . $request->getHost() . " \nRequest URL: " . $request->getUrl() . " \nPlease check your Internet connection"));
         $event->stopPropagation();
     }
     // Handle Guzzle client exceptions, i.e. HTTP 4xx errors.
     if ($exception instanceof ClientException && ($response = $exception->getResponse())) {
         $request = $exception->getRequest();
         try {
             $response->getBody()->seek(0);
             $json = $response->json();
         } catch (ParseException $e) {
             $json = [];
         }
         // Create a friendlier message for the OAuth2 "Invalid refresh token"
         // error.
         if ($response->getStatusCode() === 400 && isset($json['error_description']) && $json['error_description'] === 'Invalid refresh token') {
             $event->setException(new LoginRequiredException("Invalid refresh token: please log in again." . " \nRequest URL: " . $request->getUrl()));
             $event->stopPropagation();
         } elseif ($response->getStatusCode() === 401) {
             $event->setException(new LoginRequiredException("Unauthorized: please log in again." . " \nRequest URL: " . $request->getUrl()));
             $event->stopPropagation();
         }
     }
 }
开发者ID:ratajczak,项目名称:platformsh-cli,代码行数:36,代码来源:EventSubscriber.php

示例3: onConsoleException

 public function onConsoleException(ConsoleExceptionEvent $event)
 {
     $command = $event->getCommand();
     $exception = $event->getException();
     $message = sprintf('%s: %s (uncaught exception) at %s line %s while running console command `%s`', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $command->getName());
     $this->logger->error($message, array('exception' => $exception));
 }
开发者ID:headonkeyboard,项目名称:KunstmaanBundlesCMS,代码行数:7,代码来源:ConsoleExceptionListener.php

示例4: onConsoleException

 public function onConsoleException(ConsoleExceptionEvent $event)
 {
     $exception = $event->getException();
     //This listener only wants to deal with this particular Exception
     if (!$exception instanceof \GoCardless\Enterprise\Exceptions\ApiException) {
         return;
     }
     $output = $event->getOutput();
     $rawReasonPhrase = $exception->getReasonPhrase();
     $data = json_decode($rawReasonPhrase, true);
     $exceptionName = get_class($exception);
     $gocardlessErrorMessage = isset($data['error']['message']) ? $data['error']['message'] : 'No Gocardless error available';
     $fieldErrors = isset($data['error']['errors']) ? $data['error']['errors'] : array();
     $output->writeln("");
     $output->writeln("Exception: {$exceptionName}");
     $output->writeln("---------");
     $output->writeln("Gocardless error message: {$gocardlessErrorMessage}");
     if ($fieldErrors) {
         $output->writeln("");
         $output->writeln("Field Specific error messages");
     }
     foreach ($fieldErrors as $error) {
         $output->writeln("");
         foreach ($error as $k => $e) {
             $output->writeln("{$k}: {$e}");
         }
         $output->writeln("-----------");
     }
     $output->writeln("LOOK ABOVE FOR MORE INFORMATION ABOUT THIS EXCEPTION");
 }
开发者ID:vouchedfor,项目名称:gocardless-enterprise-bundle,代码行数:30,代码来源:ExceptionListener.php

示例5: onConsoleException

 /**
  * Logs console exception
  *
  * @param ConsoleExceptionEvent $event The event
  *
  * @return void
  */
 public function onConsoleException(ConsoleExceptionEvent $event)
 {
     $exception = $event->getException();
     $exitCode = $event->getExitCode();
     $message = sprintf('%s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine());
     $this->logger->error($message, ['exit_code' => $exitCode, 'exception' => $exception]);
 }
开发者ID:novuso,项目名称:common-bundle,代码行数:14,代码来源:ExceptionLogSubscriber.php

示例6: onConsoleException

 /**
  * Method for handling the actual exceptions
  *
  * @param  \Symfony\Component\Console\Event\ConsoleExceptionEvent $event [description]
  */
 public function onConsoleException(ConsoleExceptionEvent $event)
 {
     $command = $event->getCommand();
     $exception = $event->getException();
     $this->client->notifyOnException($exception);
     error_log(sprintf("command:%s has thrown %s in: %s:%d", $command->getName(), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
 }
开发者ID:JHGitty,项目名称:Evolution7BugsnagBundle,代码行数:12,代码来源:ConsoleListener.php

示例7:

 function it_reports_exception_on_console_exception(Notifier $notifier, \Exception $exception, ConsoleExceptionEvent $event)
 {
     $this->setException($exception);
     $event->getException()->willReturn($exception);
     $notifier->reportException($exception)->shouldBeCalled();
     $this->onConsoleException($event);
 }
开发者ID:rafalkanski,项目名称:FtrrtfRollbarBundle,代码行数:7,代码来源:RollbarListenerSpec.php

示例8: onConsoleException

 public function onConsoleException(ConsoleExceptionEvent $event)
 {
     $command = $event->getCommand();
     if (in_array($command->getName(), ['dz:notification:on_day_end'], TRUE)) {
         $exception = $event->getException();
         $message = sprintf('`%s` [uncaught exception]: command `%s` throws `%s` at `%s` line `%s`', get_class($exception), $command->getName(), $exception->getMessage(), $exception->getFile(), $exception->getLine());
         $this->logger->error($message, ['exception' => $exception]);
     }
 }
开发者ID:Kid-Binary,项目名称:Boilerplate,代码行数:9,代码来源:NotificationListener.php

示例9: onConsoleException

 /**
  * @param ConsoleExceptionEvent $event
  */
 public function onConsoleException(ConsoleExceptionEvent $event)
 {
     $exception = $event->getException();
     $metadata = new Metadata();
     $metadata->addMetadatum('commandName', $event->getInput()->getFirstArgument());
     $metadata->addMetadatum('command', (string) $event->getInput());
     $metadata->addMetadatum('exitCode', $event->getExitCode());
     $this->errorHandler->handleException($exception, $metadata);
 }
开发者ID:prgtw,项目名称:error-handler-bundle,代码行数:12,代码来源:ExceptionListener.php

示例10: onConsoleException

 /**
  * @param ConsoleExceptionEvent $event
  */
 public function onConsoleException(ConsoleExceptionEvent $event)
 {
     $command = $event->getCommand();
     $exception = $event->getException();
     // Log error with trace
     $trace = MAUTIC_ENV == 'dev' ? "\n[stack trace]\n" . $exception->getTraceAsString() : '';
     $message = sprintf('%s: %s (uncaught exception) at %s line %s while running console command `%s`%s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $command->getName(), $trace);
     // Use notice so it makes it to the log all "perttified" (using error spits it out to console and not the log)
     $this->logger->notice($message);
 }
开发者ID:dongilbert,项目名称:mautic,代码行数:13,代码来源:ConsoleExceptionListener.php

示例11: onKernelException

 /**
  * @param GetResponseForExceptionEvent|ConsoleExceptionEvent $event
  */
 public function onKernelException($event)
 {
     $exception = $event->getException();
     foreach ($this->ignoredExceptions as $ignoredException) {
         if ($exception instanceof $ignoredException) {
             return;
         }
     }
     $this->notifier->notify($exception);
 }
开发者ID:aminin,项目名称:airbrake-bundle,代码行数:13,代码来源:ExceptionListener.php

示例12: onConsoleError

 /**
  * @param ConsoleExceptionEvent $event
  */
 public function onConsoleError(ConsoleExceptionEvent $event)
 {
     $exception = $event->getException();
     $command = $event->getCommand();
     $output = $event->getOutput();
     $this->logger->error(sprintf("error while executing %s -> %s", $command->getName(), $exception->getMessage()));
     if ($this->config->get("common/debug")) {
         return;
     }
     $output->writeln(sprintf("error while executing %s -> %s", $command->getName(), $exception->getMessage()));
 }
开发者ID:digideskio,项目名称:singo,代码行数:14,代码来源:CliExceptionHandler.php

示例13: on_exception

 /**
  * This listener is run when the ConsoleEvents::EXCEPTION event is triggered.
  * It translate the exception message. If din debug mode the original exception is embedded.
  *
  * @param ConsoleExceptionEvent $event
  */
 public function on_exception(ConsoleExceptionEvent $event)
 {
     $original_exception = $event->getException();
     if ($original_exception instanceof exception_interface) {
         $parameters = array_merge(array($original_exception->getMessage()), $original_exception->get_parameters());
         $message = call_user_func_array(array($this->language, 'lang'), $parameters);
         if ($this->debug) {
             $exception = new \RuntimeException($message, $original_exception->getCode(), $original_exception);
         } else {
             $exception = new \RuntimeException($message, $original_exception->getCode());
         }
         $event->setException($exception);
     }
 }
开发者ID:MrAdder,项目名称:phpbb,代码行数:20,代码来源:exception_subscriber.php

示例14: onConsoleException

 public function onConsoleException(ConsoleExceptionEvent $event)
 {
     $exception = $event->getException();
     $exceptionId = $this->appName . '-' . md5(microtime());
     $logData = array('exception' => $exception, 'exceptionId' => $exceptionId);
     // exception is by default Application Exception
     $isUserException = false;
     // SyrupExceptionInterface holds additional data
     if ($exception instanceof SyrupExceptionInterface) {
         $logData['data'] = $exception->getData();
         $isUserException = $exception->getStatusCode() < 500;
     }
     // Log exception
     $method = $isUserException ? 'error' : 'critical';
     $this->logger->{$method}($exception->getMessage(), $logData);
 }
开发者ID:keboola,项目名称:syrup,代码行数:16,代码来源:SyrupExceptionListener.php

示例15: onException

 /**
  * React to any console exceptions.
  *
  * @param ConsoleExceptionEvent    $event
  */
 public function onException(ConsoleExceptionEvent $event)
 {
     $exception = $event->getException();
     // Replace Guzzle connect exceptions with a friendlier message. This
     // also prevents the user from seeing two exceptions (one direct from
     // Guzzle, one from RingPHP).
     if ($exception instanceof ConnectException && strpos($exception->getMessage(), 'cURL error 6') !== false) {
         $request = $exception->getRequest();
         $event->setException(new ConnectionFailedException("Failed to connect to host: " . $request->getHost() . " \nPlease check your Internet connection.", $request));
         $event->stopPropagation();
     }
     // Handle Guzzle client exceptions, i.e. HTTP 4xx errors.
     if ($exception instanceof ClientException && ($response = $exception->getResponse())) {
         $request = $exception->getRequest();
         try {
             $response->getBody()->seek(0);
             $json = $response->json();
         } catch (ParseException $e) {
             $json = [];
         }
         // Create a friendlier message for the OAuth2 "Invalid refresh token"
         // error.
         if ($response->getStatusCode() === 400 && isset($json['error_description']) && $json['error_description'] === 'Invalid refresh token') {
             $event->setException(new LoginRequiredException("Invalid refresh token: please log in again.", $request));
             $event->stopPropagation();
         } elseif ($response->getStatusCode() === 401) {
             $event->setException(new LoginRequiredException("Unauthorized: please log in again.", $request));
             $event->stopPropagation();
         } elseif ($response->getStatusCode() === 403) {
             $event->setException(new PermissionDeniedException("Permission denied. Check your project or environment permissions.", $request));
             $event->stopPropagation();
         }
     }
     // When an environment is found to be in the wrong state, perhaps our
     // cache is old - we should invalidate it.
     if ($exception instanceof EnvironmentStateException) {
         $command = $event->getCommand();
         if ($command instanceof PlatformCommand) {
             $command->clearEnvironmentsCache();
         }
     }
 }
开发者ID:CompanyOnTheWorld,项目名称:platformsh-cli,代码行数:47,代码来源:EventSubscriber.php


注:本文中的Symfony\Component\Console\Event\ConsoleExceptionEvent::getException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。