Created
January 7, 2017 13:21
-
-
Save benatespina/168a5de259c935e51c2982ebc7fe8702 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Validator | |
| { | |
| public function validateEmail($email) | |
| { | |
| if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
| throw new \Exception('Given email is not valid format email.'); | |
| } | |
| } | |
| public function validatePasswordLength($password) | |
| { | |
| if (count($password) < 6) { | |
| throw new \Exception('The given password is too short'); | |
| } | |
| if (count($password) > 20) { | |
| throw new \Exception('The given password is too long'); | |
| } | |
| } | |
| } | |
| class User | |
| { | |
| private $id; | |
| private $email; | |
| private $password; | |
| public function getId() | |
| { | |
| return $this->id; | |
| } | |
| public function getEmail() | |
| { | |
| return $this->email; | |
| } | |
| public function setEmail($email) | |
| { | |
| $this->email = $email; | |
| return $this; | |
| } | |
| public function getPassword() | |
| { | |
| return $this->password; | |
| } | |
| public function setPassword($password) | |
| { | |
| $this->password = $password; | |
| return $this; | |
| } | |
| } | |
| $user = new User(); | |
| $userValidator = new Validator(); | |
| $userValidator->validateEmail($email); | |
| $userValidator->validatePasswordLength($password); | |
| $user->setEmail($email); | |
| $user->setPassword($password); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment