Skip to content

Commit

Permalink
[UPDATE] Add the getException method in Zend\Soap\Server override
Browse files Browse the repository at this point in the history
  • Loading branch information
lilobase committed Feb 9, 2014
1 parent d1ede90 commit 5ca0f50
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
17 changes: 15 additions & 2 deletions README.md
Expand Up @@ -23,7 +23,7 @@ For more informations about Zend Soap, check the Zend Framework documentation :

##Usages

###Basic usages
###Basic use

When the service provider is registered, you have access to the two basic services :
* **soap.server**, instance of Zend\Soap\Server`
Expand Down Expand Up @@ -61,7 +61,7 @@ $app['soap.instances'] = array(
);
```

You have access to you instances with the two services :
You have access to your instances with the two services :
* `soap.clients`
* `soap.servers`

Expand Down Expand Up @@ -137,6 +137,8 @@ So the serviceProvider extends the `DotNet` class to add a `exists` condition on

### In `\Zend\Soap\Server`

#### Debug mode

When an exception is raised in your code the `\Zend\Soap\Server` catch it and check if this is an authorized exception. If not, and for security reason, it send an "Unknow error" message. And if in production its a sane behavior, its really annoying during development & tests process.

So the serviceProvider extends the `Server` class to add a `debugMode` method which is automatically activated when the silex `debug` options is `true` (manual enable/disable debug mode is provide with the `setDebugMode($boolean)` server method).
Expand All @@ -152,6 +154,17 @@ $app['soap.server']->setDebugMode(false);

**In debug mode the Server send all exceptions to the soap client.**

#### Exception management

As described below, when an exception is catch by the `Zend\Soap\Server`, the error message became "Unknown error". So even if you write the exception in logs, you have no ideas of the failure root cause, to avoid this trouble a `getException` method is available in the provider's server class.
Ecample :

```php
$app['soap.server']->fault(new \Exception('test'));

$app['soap.server']->getException(); //return the Exception instance given as attribute to the fault method.
```

##Advanced topic

###Change Soap class
Expand Down
16 changes: 16 additions & 0 deletions src/Ibsciss/Zend/Soap/Server.php
Expand Up @@ -11,6 +11,11 @@ class Server extends \Zend\Soap\Server
*/
protected $debug = false;

/**
* catch exception during soap request
* @var \Exception
*/
protected $exception = null;
/**
* Set the debug mode.
* In debug mode, all exceptions are send to the client.
Expand All @@ -31,4 +36,15 @@ public function isRegisteredAsFaultException($fault)
{
return ($this->debug) ? true : parent::isRegisteredAsFaultException($fault);
}

public function fault($fault = null, $code = 'Receiver')
{
$this->exception = (is_string($fault)) ? new \Exception($fault) : $fault;
return parent::fault($fault, $code);
}

public function getException()
{
return $this->exception;
}
}
Expand Up @@ -246,7 +246,7 @@ public function testDotNetClientDefaultOverride()
$this->assertInstanceOf('\Ibsciss\Zend\Soap\Client\DotNet', $app['soap.client']);
}

public function test__preProcessResult()
public function test_preProcessResult()
{
$app = $this->getApplication();
$app['soap.dotNet'] = true;
Expand Down Expand Up @@ -274,6 +274,20 @@ public function test__preProcessResult()
$this->assertEquals($parameters->testCallResult, $result);
}

public function testExceptionOverride()
{
$app = $this->getApplication();
$server = $app['soap.server'];
$fault = $server->fault(new \Exception('test'));

$exception = $server->getException();
$this->assertInstanceOf('\Exception', $exception);
$this->assertEquals('test', $exception->getMessage());

$this->assertInstanceOf('\SoapFault', $fault);
$this->assertEquals('Unknown error', $fault->getMessage());
}

public function getApplication()
{
$app = new Application();
Expand Down

0 comments on commit 5ca0f50

Please sign in to comment.