Merge pull request #334 from filp/separate-soap-handler

Move SOAP handler out
This commit is contained in:
Denis Sokolov
2015-12-13 01:08:35 +02:00
4 changed files with 4 additions and 124 deletions
+2 -1
View File
@@ -79,7 +79,8 @@ For more options, have a look at the **example files** in `examples/` to get a f
- [`CallbackHandler`](https://github.com/filp/whoops/blob/master/src/Whoops/Handler/CallbackHandler.php) - Wraps a closure or other callable as a handler. You do not need to use this handler explicitly, **whoops** will automatically wrap any closure or callable you pass to `Whoops\Run::pushHandler`
- [`JsonResponseHandler`](https://github.com/filp/whoops/blob/master/src/Whoops/Handler/JsonResponseHandler.php) - Captures exceptions and returns information on them as a JSON string. Can be used to, for example, play nice with AJAX requests.
- [`XmlResponseHandler`](https://github.com/filp/whoops/blob/master/src/Whoops/Handler/XmlResponseHandler.php) - Captures exceptions and returns information on them as a XML string. Can be used to, for example, play nice with AJAX requests.
- [`SoapResponseHandler`](https://github.com/filp/whoops/blob/master/src/Whoops/Handler/SoapResponseHandler.php) - Captures exceptions and returns information on them as a SOAP string. Might be used for SOAP Webservices.
You can also use pluggable handlers, such as [SOAP handler](https://github.com/whoops-php/soap).
## Authors
+2 -1
View File
@@ -19,7 +19,8 @@
"mockery/mockery": "0.9.*"
},
"suggest": {
"symfony/var-dumper": "^2.6"
"symfony/var-dumper": "^2.6",
"whoops/soap": "Formats errors as SOAP responses"
},
"autoload": {
"psr-4": {
@@ -1,49 +0,0 @@
<?php
/**
* Whoops - php errors for cool kids
* @author Filipe Dobreira <http://github.com/filp>
*/
namespace Whoops\Handler;
/**
* Catches an exception and converts it to an Soap XML
* response.
*
* @author Markus Staab <http://github.com/staabm>
*/
class SoapResponseHandler extends Handler
{
/**
* @return int
*/
public function handle()
{
$exception = $this->getException();
echo $this->toXml($exception);
return Handler::QUIT;
}
/**
* Converts a Exception into a SoapFault XML
*/
private function toXml(\Exception $exception)
{
$xml = '';
$xml .= '<?xml version="1.0" encoding="UTF-8"?>';
$xml .= '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">';
$xml .= ' <SOAP-ENV:Body>';
$xml .= ' <SOAP-ENV:Fault>';
$xml .= ' <faultcode>'. htmlspecialchars($exception->getCode()) .'</faultcode>';
$xml .= ' <faultstring>'. htmlspecialchars($exception->getMessage()) .'</faultstring>';
$xml .= ' <detail><trace>'. htmlspecialchars($exception->getTraceAsString()) .'</trace></detail>';
$xml .= ' </SOAP-ENV:Fault>';
$xml .= ' </SOAP-ENV:Body>';
$xml .= '</SOAP-ENV:Envelope>';
return $xml;
}
}
@@ -1,73 +0,0 @@
<?php
/**
* Whoops - php errors for cool kids
*/
namespace Whoops\Handler;
use RuntimeException;
use Whoops\TestCase;
class SoapResponseHandlerTest extends TestCase
{
public function testSimpleValid()
{
$handler = new SoapResponseHandler();
$run = $this->getRunInstance();
$run->pushHandler($handler);
$run->register();
ob_start();
$run->handleException($this->getException());
$data = ob_get_clean();
$this->assertTrue($this->isValidXml($data));
return simplexml_load_string($data);
}
/**
* @depends testSimpleValid
*/
public function testSimpleValidCode(\SimpleXMLElement $xml)
{
$this->checkField($xml, 'faultcode', (string) $this->getException()->getCode());
}
/**
* @depends testSimpleValid
*/
public function testSimpleValidMessage(\SimpleXMLElement $xml)
{
$this->checkField($xml, 'faultstring', $this->getException()->getMessage());
}
/**
* Helper for testSimpleValid*
*/
private function checkField(\SimpleXMLElement $xml, $field, $value)
{
$list = $xml->xpath('/SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/'.$field);
$this->assertArrayHasKey(0, $list);
$this->assertSame($value, (string) $list[0]);
}
private function getException()
{
return new RuntimeException('boom', 678);
}
/**
* See if passed string is a valid XML document
* @param string $data
* @return bool
*/
private function isValidXml($data)
{
$prev = libxml_use_internal_errors(true);
$xml = simplexml_load_string($data);
libxml_use_internal_errors($prev);
return $xml !== false;
}
}