本文整理汇总了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;
}
示例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;
}
}
示例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);
}
}
示例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;
}