Created
March 19, 2019 16:40
-
-
Save vsguts/92cbb971645265bcf45f739da49bc24f 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 User | |
{ | |
private $name; | |
public function setName($name) | |
{ | |
$this->name = $name; | |
} | |
public function getName() | |
{ | |
return $this->name; | |
} | |
} | |
class Employee extends User | |
{ | |
public $role = 'employee'; | |
} | |
class Catalog | |
{ | |
private $users = []; | |
public function addUser(User $user) | |
{ | |
$this->users[] = $user; | |
} | |
public function getNames() | |
{ | |
foreach ($this->users as $user) { | |
echo $user->getName() . PHP_EOL; | |
} | |
} | |
} | |
$user = new User; | |
$user->setName('Vladimir Guts'); | |
$user2 = new Employee; | |
$user2->setName('Dmitry Golub'); | |
$user2->role = 'manager'; | |
$catalog = new Catalog; | |
$catalog->addUser($user); | |
$catalog->addUser($user2); | |
$catalog->getNames(); | |
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 Notifier | |
{ | |
private $channel = 'slack'; | |
public function notify($notification) | |
{ | |
if ($this->channel == 'slack') { | |
$this->sendViaSlack($notification); | |
} elseif ($this->channel == 'email') { | |
$this->sendViaEmail($notification); | |
} | |
} | |
private function sendViaSlack($notification) {} | |
private function sendViaEmail($notification) {} | |
} | |
$notification = new Notifier(); | |
$notification->notify("Hello"); |
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 Auth | |
{ | |
public function login($username, $password) | |
{ | |
$user = $this->getUserData($username, $password); | |
if ($user) { | |
$this->auth($user); | |
} | |
} | |
public function getUserData($user, $password) | |
{ | |
$dbUser = $this->db("SELECT * FROM users WHERE username = '" . $user . "'"); | |
if ($dbUser['password'] == $password) { | |
return $dbUser; | |
} | |
} | |
public function auth($user) | |
{ | |
$_SESSION['auth'] = $user; | |
$this->log('User was logged in'); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment