Created
August 1, 2015 07:04
-
-
Save revathskumar/9abda2bf7562a18ab317 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Service { | |
public function create() { | |
print "In service create\n"; | |
//try { | |
$this->send(); | |
//} | |
//catch(ServiceException $e) { | |
// print "catch service exception in create\n"; | |
//} | |
//throw new ServiceException('Service can\'t be created due to this reason'); | |
} | |
private function send() { | |
print "In service send\n"; | |
throw new ServiceException('Service can\'t send email due to this reason!!'); | |
} | |
} | |
class ServiceException extends Exception { | |
} | |
class ServiceAException extends Exception { | |
} | |
class ServiceA { | |
public function create() { | |
print "ServiceA :: create \n"; | |
print $this->send(); | |
} | |
private function send() { | |
print "ServiceA :: send \n"; | |
throw new ServiceAException('ServiceA can\'t send email due to this reason!!'); | |
} | |
} | |
class Wrapper { | |
var $service; | |
function __construct($service) { | |
$this->service = $service; | |
} | |
public function create(){ | |
$result = ['status' => '', 'message' => '']; | |
try { | |
$this->service->create(); | |
$result['status'] = 'success'; | |
$result['message'] = 'service calls are success'; | |
} | |
catch(ServiceException $e) { | |
print "catch ServiceException :: {$e->getMessage()}\n"; | |
$result['status'] = 'error'; | |
$result['message'] = $e->getMessage(); | |
} | |
catch(ServiceAException $e) { | |
print "catch ServiceAException :: {$e->getMessage()}\n"; | |
$result['status'] = 'error'; | |
$result['message'] = $e->getMessage(); | |
} | |
print json_encode($result); | |
print "\n"; | |
} | |
} | |
$service = new Service; | |
$serviceA = new ServiceA; | |
$wrapper = new Wrapper($service); | |
$wrapper->create(); | |
$wrapperA = new Wrapper($serviceA); | |
$wrapperA->create(); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment