forked from DesignPatternsPHP/DesignPatternsPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnection.php
More file actions
35 lines (31 loc) · 756 Bytes
/
Connection.php
File metadata and controls
35 lines (31 loc) · 756 Bytes
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
<?php
namespace DesignPatterns\DependencyInjection;
/**
* Class Connection
*/
class Connection
{
/**
* @var Configuration
*/
protected $configuration;
/**
* here, Configuration gets injected and Connection will get all that it needs from Configuration
* without DI, the configuration would be created directly in Connection, which is not very good
* for testing and extending Connection
*
* @param Configuration $config
*/
public function __construct(Configuration $config)
{
$this->configuration = $config;
}
/**
* connection using the injected config
*/
public function connect()
{
$host = $this->configuration->getHost();
// ...
}
}