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


PHP Exception::getId方法代码示例

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


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

示例1: createHttpResponseFromException

 /**
  * Create new HttpResponse from exception.
  *
  * @param \Exception $exception
  *
  * @return HttpResponse
  */
 protected function createHttpResponseFromException(\Exception $exception)
 {
     $httpResponse = HttpResponse::create();
     $json = [];
     $json['jsonrpc'] = '2.0';
     $json['error'] = [];
     if ($exception instanceof Exceptions\ErrorException) {
         $json['error']['code'] = $exception->getCode();
         $json['error']['message'] = $exception->getMessage();
         if ($exception->getData()) {
             $json['error']['data'] = $exception->getData();
         }
         $json['id'] = $exception->getId();
     } else {
         $json['error']['code'] = -32603;
         $json['error']['message'] = 'Internal error';
         $json['id'] = null;
     }
     $httpResponse->headers->set('Content-Type', 'application/json');
     $httpResponse->setContent(json_encode($json));
     $httpResponse->setStatusCode(500);
     return $httpResponse;
 }
开发者ID:timiki,项目名称:rpc-server-bundle,代码行数:30,代码来源:Handler.php

示例2: solve

 public function solve(Request $request, \Exception $exception)
 {
     if (!$exception instanceof ServiceNotFoundException) {
         return null;
     }
     try {
         $finder = new ObjectFinder();
         $container = $finder->find('Symfony\\Component\\DependencyInjection\\Container');
         $ids = $container->getServiceIds();
         $searchedId = $exception->getId();
         $similarity = array();
         foreach ($ids as $id) {
             $percentage = 0.0;
             similar_text($id, $searchedId, $percentage);
             if ($percentage >= 90.0) {
                 $similarity[$id] = $percentage;
             }
         }
         arsort($similarity);
         if (!$similarity) {
             return null;
         }
         return new SimpleBlockSolution('Do you have a typo in the service name?', 'Solution:service_name_typo.html.php', array('serviceIds' => $similarity));
     } catch (\Exception $ex) {
         return null;
     }
 }
开发者ID:richardmiller,项目名称:DebuggingBundle,代码行数:27,代码来源:ServiceNotFoundProblemSolver.php

示例3: notify

 public function notify(\Exception $exception)
 {
     if (!$exception instanceof ServiceNotFoundException) {
         return;
     }
     $serviceId = $exception->getId();
     $guessedFqcn = $this->guessFqcn($serviceId);
     $definition = new Definition();
     $definition->setClass($guessedFqcn);
     $containerBuilder = new ContainerBuilder();
     $containerBuilder->addDefinitions([$serviceId => $definition]);
     $dumper = new YamlDumper($containerBuilder);
     $result = $dumper->dump();
     $message = sprintf('Service `%s` missing. Define it in your services.yml:', $serviceId);
     $this->output->writeln('--- ' . $message . PHP_EOL);
     $this->output->write($result, true);
     $errorMessages = ['Service ' . $serviceId . ' was not found.'];
     $formatter = new FormatterHelper();
     $formattedBlock = $formatter->formatBlock($errorMessages, 'error', true);
     $this->output->writeln('');
     $this->output->writeln($formattedBlock);
     $this->output->writeln('');
     $question = sprintf('<question>Do you want to create a specification for %s? (Y/n)</question>', $guessedFqcn);
     $dialog = new DialogHelper();
     if ($dialog->askConfirmation($this->output, $question, true)) {
         $this->specRunner->runDescCommand($guessedFqcn);
     }
 }
开发者ID:kix,项目名称:behat-sf2-service-generator,代码行数:28,代码来源:NonExistentServiceObserver.php

示例4: generateDefaultOutput

 /**
  * generates the default error output
  *
  * @author Daniel Sherman
  * @param \Exception $e The exception thats needs to be outputted
  * @return string the default output
  */
 public function generateDefaultOutput(\Exception $e)
 {
     $message = 'Issue: ';
     if ($e instanceof ExceptionInterface) {
         $message .= $e->getId();
     }
     $interface = php_sapi_name();
     if (substr($interface, 0, 3) != 'cli') {
         // this can't really be unit tested tested
         // it should be noted that the response code will be ignored
         // if data has already been sent to the browser.
         http_response_code(500);
     }
     return $message;
 }
开发者ID:flairphp,项目名称:flair,代码行数:22,代码来源:Handler.php


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