This repository was archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathv3.php
More file actions
59 lines (51 loc) · 1.19 KB
/
v3.php
File metadata and controls
59 lines (51 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
class App
{
protected $auth = null;
protected $session = null;
public function __construct(Auth $auth, Session $session)
{
$this->auth = $auth;
$this->session = $session;
}
public function login($username, $password)
{
if ($this->auth->check($username, $password)) {
$this->session->set('username', $username);
return true;
}
return false;
}
}
interface Auth
{
public function check($username, $password);
}
class DbAuth implements Auth
{
public function __construct($dsn, $user, $pass)
{
echo "Connecting to '$dsn' with '$user'/'$pass'...\n";
sleep(1);
}
public function check($username, $password)
{
echo "Checking username, password from database...\n";
sleep(1);
return true;
}
}
class Session
{
public function set($name, $value)
{
echo "Set session variable '$name' to '$value'.\n";
}
}
$auth = new DbAuth('mysql://localhost', 'root', '123456');
$session = new Session();
$app = new App($auth, $session);
$username = 'jaceju';
if ($app->login($username, 'password')) {
echo "$username just signed in.\n";
}