Created
July 19, 2010 18:46
-
-
Save yuxel/481801 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
class Service_Exception | |
{ | |
private $errors; | |
public put($errorCode, $errrorMessage="Undefined" ) | |
{ | |
array_push( | |
} | |
public throwIfAnyException() | |
{ | |
if ( !empty($errors)) { | |
throw new Exception(serialize($errors); | |
} | |
} | |
public static resolveExceptions($errors) { | |
return unserialize($errors); | |
} | |
} | |
abstract class Service_Common_Abstract | |
{ | |
private $serviceException; | |
public __construct() { | |
$this->serviceException = new ServiceException(); | |
} | |
} | |
class UserService extends Service_Common_Abstract implements UserService_Interface{ | |
public function register() { | |
if ( $this->isUserExists($user) ) { | |
$this->serviceException->put(1,"USER_ALREADY_EXISTS"); | |
} | |
if ( $this->isEmailExists($User) ) { | |
$this->serviceException->put(2,"EMAIL_ALREADY_EXISTS"); | |
} | |
$this->serviceException->throwIfAnyException(); | |
} | |
} | |
class userController { | |
function index() { | |
try { | |
$user = new ServiceUser(); | |
$user->register($user); | |
} | |
catch(Exception $e) { | |
Service_Exception::resolveException($e->getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment