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


PHP RuntimeException::getCode方法代码示例

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


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

示例1: logError

 /**
  * @param \Zend\Mvc\MvcEvent $oEvent
  * @return \BoilerAppLogger\Logger\MvcLogger
  */
 public function logError(\Zend\Mvc\MvcEvent $oEvent)
 {
     //Create log error
     $oLogError = new \BoilerAppLogger\Entity\LogErrorEntity();
     if (!($oException = $oEvent->getParam('exception')) instanceof \Exception) {
         if (!($oResponse = $oEvent->getResponse()) instanceof \Zend\Http\Response) {
             throw new \LogicException(sprintf('Response expects an instance of \\Zend\\Http\\Response, "%s" given', is_object($oResponse) ? get_class($oResponse) : gettype($oResponse)));
         }
         $oException = new \RuntimeException($oEvent->getError(), $oResponse->getStatusCode());
     } else {
         $oLogError->setLogErrorFile($oException->getFile())->setLogErrorLine($oException->getLine());
     }
     $this->getLogErrorRepository()->create($oLogError->setLogErrorMessage($oException->getMessage())->setLogErrorCode($oException->getCode())->setLogErrorTrace($oException->getTraceAsString())->setLogErrorLog($this->getCurrentLog()));
     return $this;
 }
开发者ID:zf2-boiler-app,项目名称:app-logger,代码行数:19,代码来源:MvcLogger.php

示例2: testCreateWithExceptionWithPrevious

 /**
  * Log events also take an exception as message argument (here with previous exception)
  */
 public function testCreateWithExceptionWithPrevious()
 {
     $logEvent = LogEvent::create(ILogger::LEVEL_ERROR, $this->invargEx, array(), 'PHPUnit');
     $logEventData = $logEvent->getArrayCopy();
     $this->assertNotEmpty($logEventData);
     $this->assertInternalType('array', $logEventData);
     $this->assertArrayHasKey('msg', $logEventData);
     $this->assertArrayHasKey('exception', $logEventData);
     $this->assertEquals($this->invargEx->getMessage(), $logEventData['msg']);
     $this->assertNotEmpty($logEventData['exception']);
     $this->assertInternalType('array', $logEventData['exception']);
     $exceptionArray = $logEventData['exception'];
     $this->assertArrayHasKey('file', $exceptionArray);
     $this->assertArrayHasKey('message', $exceptionArray);
     $this->assertArrayHasKey('code', $exceptionArray);
     $this->assertArrayHasKey('line', $exceptionArray);
     $this->assertArrayHasKey('trace', $exceptionArray);
     $this->assertArrayHasKey('previous', $exceptionArray);
     $this->assertEquals(__FILE__, $exceptionArray['file']);
     $this->assertEquals($this->invargEx->getMessage(), $exceptionArray['message']);
     $this->assertEquals($this->invargEx->getCode(), $exceptionArray['code']);
     $this->assertEquals($this->invargEx->getLine(), $exceptionArray['line']);
     $this->assertNotEmpty($exceptionArray['trace']);
     $previousArray = $exceptionArray['previous'];
     $this->assertArrayHasKey('file', $previousArray);
     $this->assertArrayHasKey('message', $previousArray);
     $this->assertArrayHasKey('code', $previousArray);
     $this->assertArrayHasKey('line', $previousArray);
     $this->assertArrayHasKey('trace', $previousArray);
     $this->assertArrayNotHasKey('previous', $previousArray);
     $this->assertEquals(__FILE__, $previousArray['file']);
     $this->assertEquals($this->runtimeEx->getMessage(), $previousArray['message']);
     $this->assertEquals($this->runtimeEx->getCode(), $previousArray['code']);
     $this->assertEquals($this->runtimeEx->getLine(), $previousArray['line']);
     $this->assertNotEmpty($previousArray['trace']);
 }
开发者ID:zalora,项目名称:punyan,代码行数:39,代码来源:LogEventTest.php

示例3: testDefFormatWithPreviousException

 public function testDefFormatWithPreviousException()
 {
     $formatter = new JsonFormatter();
     $exception = new \RuntimeException('Foo', 0, new \LogicException('Wut?'));
     $message = $formatter->format(array('level_name' => 'CRITICAL', 'channel' => 'core', 'context' => array('exception' => $exception), 'datetime' => new \DateTime(), 'extra' => array(), 'message' => 'foobar'));
     if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
         $pathPrevious = substr(json_encode($exception->getPrevious()->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
         $pathException = substr(json_encode($exception->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
     } else {
         $pathPrevious = substr(json_encode($exception->getPrevious()->getFile()), 1, -1);
         $pathException = substr(json_encode($exception->getFile()), 1, -1);
     }
     $this->assertEquals('{"level_name":"CRITICAL","channel":"core","context":{"exception":{"class":"RuntimeException","message":"' . $exception->getMessage() . '","code":' . $exception->getCode() . ',"file":"' . $pathException . ':' . $exception->getLine() . '","previous":{"class":"LogicException","message":"' . $exception->getPrevious()->getMessage() . '","code":' . $exception->getPrevious()->getCode() . ',"file":"' . $pathPrevious . ':' . $exception->getPrevious()->getLine() . '"}}},"datetime":' . json_encode(new \DateTime()) . ',"extra":[],"message":"foobar"}' . "\n", $message);
 }
开发者ID:jorjoh,项目名称:Varden,代码行数:14,代码来源:JsonFormatterTest.php

示例4: _actionException

 /**
  * Callback to handle both JError and Exception
  * 
  * @param KCommandContext $context Command chain context
  * caller => KObject, data => mixed
  * 
  * @return KException
  */
 protected function _actionException($context)
 {
     $exception = $context->data;
     //if JException then conver it to KException
     if ($exception instanceof JException) {
         $exception = new RuntimeException($exception->getMessage(), $exception->getCode());
     }
     //if cli just print the error and exit
     if (PHP_SAPI == 'cli') {
         print "\n";
         print $exception . "\n";
         print debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
         exit(0);
     }
     $code = $exception->getCode();
     //check if the error is code is valid
     if ($code < 400 || $code >= 600) {
         $code = KHttpResponse::INTERNAL_SERVER_ERROR;
     }
     $context->response->status = $code;
     $config = array('response' => $context->response, 'request' => $context->request, 'theme' => $this->_application->getTemplate());
     //if ajax or the format is not html
     //then return the exception in json format
     if ($context->request->isAjax() || $context->request->getFormat() != 'html') {
         $context->request->setFormat('json');
     }
     $this->getService('com://site/application.controller.exception', $config)->layout('error')->render($exception);
     $this->send($context);
 }
开发者ID:walteraries,项目名称:anahita,代码行数:37,代码来源:dispatcher.php

示例5: produce

 /**
  * Publishes a message to the backend.
  *
  * @param Message $message
  * @return void
  * @throws \RuntimeException If publishing fails
  */
 public function produce(Message $message)
 {
     $type = $message->getType();
     $body = array('ticket' => $message->getTicket());
     try {
         $this->logger->debug(sprintf('Publish message for job %s to sonata backend', $message->getTicket()), ['type' => $type, 'body' => $body]);
         $queue = $this->registry->get($message->getType())->getQueue();
         $this->backendProvider->getBackend($queue)->createAndPublish($type, $body);
     } catch (\Exception $e) {
         $this->logger->error(sprintf('Failed to publish message (Error: %s)', $e->getMessage()), ['exception' => $e]);
         if (!$e instanceof \RuntimeException) {
             $e = new \RuntimeException($e->getMessage(), $e->getCode(), $e);
         }
         throw $e;
     }
 }
开发者ID:aboutcoders,项目名称:job-bundle,代码行数:23,代码来源:ProducerAdapter.php

示例6: connect

 /**
  *  connect to the db
  *  
  *  @param  MingoConfig $config
  *  @return boolean
  */
 public function connect(MingoConfig $config = null)
 {
     if (!empty($config)) {
         $this->setConfig($config);
     }
     //if
     $this->connected = false;
     try {
         // actually connect to the interface...
         $this->connected = $this->_connect($this->getConfig());
         if ($this->hasDebug()) {
             if (!is_bool($this->connected)) {
                 throw new UnexpectedValueException(sprintf('_%s() expected to return type: boolean, got: %s', __FUNCTION__, gettype($this->connected)));
             }
             //if
         }
         //if
     } catch (Exception $e) {
         if ($this->hasDebug()) {
             $e_msg = array();
             $msg = array();
             foreach ($config as $key => $val) {
                 $msg[] = sprintf('[%s] => %s', $key, empty($val) ? '""' : $val);
             }
             //foreach
             $e_msg[] = sprintf('db connection failed with message "%s" and connection variables: %s', $e->getMessage(), join(',', $msg));
             $e = new RuntimeException(join(PHP_EOL, $e_msg), $e->getCode(), $e);
         }
         //if
         $this->handleException($e);
     }
     //try/catch
     return $this->connected;
 }
开发者ID:Jaymon,项目名称:Mingo,代码行数:40,代码来源:MingoInterface.php


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