From 1c0bf6f719706d022db633db2aae9545675629d6 Mon Sep 17 00:00:00 2001 From: Arnaud LEMAIRE Date: Thu, 6 Feb 2014 15:12:02 +0200 Subject: [PATCH 1/4] [Soap/Server] add debug mode --- library/Zend/Soap/Server.php | 17 +++++++++++++++++ tests/ZendTest/Soap/ServerTest.php | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/library/Zend/Soap/Server.php b/library/Zend/Soap/Server.php index 21584927eb6..b9b8fb941d7 100644 --- a/library/Zend/Soap/Server.php +++ b/library/Zend/Soap/Server.php @@ -74,6 +74,12 @@ class Server implements ZendServerServer */ protected $object; + /** + * Informs if the soap server is in debug mode + * @var boolean + */ + protected $debug = false; + /** * Persistence mode; should be one of the SOAP persistence constants * @var int @@ -925,6 +931,15 @@ protected function _initializeSoapErrorContext() return $displayErrorsOriginalState; } + /** + * Set the debug mode. + * In debug mode, all exceptions are send to the client. + * @param boolean $debug + */ + public function setDebugMode($debug = true) + { + $this->debug = $debug; + } /** * Validate and register fault exception * @@ -961,6 +976,8 @@ public function registerFaultException($class) */ public function isRegisteredAsFaultException($fault) { + if($this->debug) return true ; + $ref = new ReflectionClass($fault); $classNames = $ref->getName(); return in_array($classNames, $this->faultExceptions); diff --git a/tests/ZendTest/Soap/ServerTest.php b/tests/ZendTest/Soap/ServerTest.php index df4dce4ae1f..653f48c4c4d 100644 --- a/tests/ZendTest/Soap/ServerTest.php +++ b/tests/ZendTest/Soap/ServerTest.php @@ -937,4 +937,15 @@ public function testShouldThrowExceptionIfHandledRequestContainsDoctype() $this->assertContains('Invalid XML', $response->getMessage()); } + public function testDebugMode() + { + $server = new Server(); + $beforeDebug = $server->fault(new \Exception('test')); + $server->setDebugMode(); + $afterDebug = $server->fault(new \Exception('test')); + + $this->assertEquals('Unknown error', $beforeDebug->getMessage()); + $this->assertEquals('test', $afterDebug->getMessage()); + } + } From 5ace0d75797e3ec60e97a94a5853fc2dd0678835 Mon Sep 17 00:00:00 2001 From: Arnaud LEMAIRE Date: Thu, 6 Feb 2014 16:48:47 +0200 Subject: [PATCH 2/4] [FIX] Consistent docblock args type & PSR-2 code formatting --- library/Zend/Soap/Server.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/Zend/Soap/Server.php b/library/Zend/Soap/Server.php index b9b8fb941d7..1d077ff9c60 100644 --- a/library/Zend/Soap/Server.php +++ b/library/Zend/Soap/Server.php @@ -76,7 +76,7 @@ class Server implements ZendServerServer /** * Informs if the soap server is in debug mode - * @var boolean + * @var bool */ protected $debug = false; @@ -934,7 +934,7 @@ protected function _initializeSoapErrorContext() /** * Set the debug mode. * In debug mode, all exceptions are send to the client. - * @param boolean $debug + * @param bool $debug */ public function setDebugMode($debug = true) { @@ -976,7 +976,7 @@ public function registerFaultException($class) */ public function isRegisteredAsFaultException($fault) { - if($this->debug) return true ; + if ($this->debug) return true; $ref = new ReflectionClass($fault); $classNames = $ref->getName(); From 8d53e506b11f5562b768f4eecd79f342fcd45d11 Mon Sep 17 00:00:00 2001 From: Arnaud LEMAIRE Date: Sat, 8 Feb 2014 15:05:59 +0200 Subject: [PATCH 3/4] [FIX] if formatting --- library/Zend/Soap/Server.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/Zend/Soap/Server.php b/library/Zend/Soap/Server.php index 1d077ff9c60..86c5928bf06 100644 --- a/library/Zend/Soap/Server.php +++ b/library/Zend/Soap/Server.php @@ -976,7 +976,9 @@ public function registerFaultException($class) */ public function isRegisteredAsFaultException($fault) { - if ($this->debug) return true; + if ($this->debug) { + return true; + } $ref = new ReflectionClass($fault); $classNames = $ref->getName(); From d704a8ab5de784da063e334da99d996787fe33bd Mon Sep 17 00:00:00 2001 From: Arnaud LEMAIRE Date: Fri, 28 Feb 2014 02:07:40 +0200 Subject: [PATCH 4/4] [UPDATE] add fluent interface & cs fix --- library/Zend/Soap/Server.php | 4 +++- tests/ZendTest/Soap/ServerTest.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/library/Zend/Soap/Server.php b/library/Zend/Soap/Server.php index 86c5928bf06..0f1b2047bf9 100644 --- a/library/Zend/Soap/Server.php +++ b/library/Zend/Soap/Server.php @@ -936,10 +936,12 @@ protected function _initializeSoapErrorContext() * In debug mode, all exceptions are send to the client. * @param bool $debug */ - public function setDebugMode($debug = true) + public function setDebugMode($debug) { $this->debug = $debug; + return $this; } + /** * Validate and register fault exception * diff --git a/tests/ZendTest/Soap/ServerTest.php b/tests/ZendTest/Soap/ServerTest.php index 653f48c4c4d..52b3c3c0284 100644 --- a/tests/ZendTest/Soap/ServerTest.php +++ b/tests/ZendTest/Soap/ServerTest.php @@ -941,7 +941,7 @@ public function testDebugMode() { $server = new Server(); $beforeDebug = $server->fault(new \Exception('test')); - $server->setDebugMode(); + $server->setDebugMode(true); $afterDebug = $server->fault(new \Exception('test')); $this->assertEquals('Unknown error', $beforeDebug->getMessage());