Created
March 31, 2014 21:33
-
-
Save imjacobclark/9902869 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
<?php | |
// Classes vs Objects | |
class User{ | |
private $email; | |
private $password; | |
const MINCHARS = 8; | |
public function login(){ | |
return "Logging in"; | |
} | |
public function logout(){ | |
return "Logging out"; | |
} | |
public function setEmail($e){ | |
if(filter_var($this->email, FILTER_VALIDATE_EMAIL) ){ | |
throw new Exception("A none valid email was provided"); | |
} | |
$this->email = $e; | |
} | |
public function getEmail(){ | |
return $this->email; | |
} | |
public function setPassword($p){ | |
if(!$this->validatePassword($p)){ | |
throw new Exception('The password should be '.self::MINCHARS.' chars long'); | |
} | |
$this->password = hash('sha256', $p); | |
} | |
public function getPassword(){ | |
return $this->password; | |
} | |
private function validatePassword($p){ | |
return strlen($p) < self::MINCHARS ? false : true; | |
} | |
} | |
$user = new User(); | |
$user->setEmail("[email protected]"); | |
$user->setPassword('helloworld'); | |
echo $user->login(); | |
echo $user->logout(); | |
echo $user->getPassword(); | |
var_dump($user); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment