forked from DesignPatternsPHP/DesignPatternsPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration.php
More file actions
45 lines (40 loc) · 1.02 KB
/
Configuration.php
File metadata and controls
45 lines (40 loc) · 1.02 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
<?php
namespace DesignPatterns\DependencyInjection;
/**
* Dependency Injection
*
* Purpose:
* to implement a loosely coupled architecture in order to get better testable, maintainable and extendable code
*
* Examples:
* - the Doctrine2 ORM uses dependency injection e.g. for Configuration that is injected into a Connection object. for
* testing purposes, one can easily create a mock object of the configuration and inject that into the connection
* object
* - Symfony and Zend Framework 2 already have containers for DI that create objects via a configuration array and
* inject them where needed (i.e. in Controllers)
*
*/
class Configuration
{
/**
* @var string
*/
protected $host;
/**
* @param string $host
*
* @return Configuration
*/
public function setHost($host)
{
$this->host = $host;
return $this; // for a fluent interface
}
/**
* @return string
*/
public function getHost()
{
return $this->host;
}
}