-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindex.php
More file actions
74 lines (63 loc) · 1.33 KB
/
index.php
File metadata and controls
74 lines (63 loc) · 1.33 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* Design pattern "Dependency injection" (Structural)
* This is demo code
* See for details: http://maxsite.org/page/php-di
* https://en.wikipedia.org/wiki/Dependency_injection
*/
// type Configuration
interface ConfigurationInterface
{
public function getKey1();
public function getKey2();
}
// class for configuration
class ConfigurationOne implements ConfigurationInterface
{
private $key1;
private $key2;
public function __construct($key1, $key2)
{
$this->key1 = $key1;
$this->key2 = $key2;
}
public function getKey1()
{
return $this->key1;
}
public function getKey2()
{
return $this->key2;
}
}
// Connection use Configuration data
class Connection
{
private $configuration;
public function __construct(ConfigurationInterface $config)
{
$this->configuration = $config;
}
// something to do
public function run()
{
return [
$this->configuration->getKey1(),
$this->configuration->getKey2()
];
}
}
/**
* demo
*/
$config = new ConfigurationOne('myKey1', 'myKey2');
$connection = new Connection($config);
echo '<pre>';
print_r($connection->run());
/*
Array (
[0] => myKey1
[1] => myKey2
)
*/
# end of file