Created
February 15, 2015 21:45
-
-
Save ogabrielsantos/c75ad3baae407257d29b to your computer and use it in GitHub Desktop.
In reply to http://stackoverflow.com/a/16856502/744255
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 | |
interface DataManagement | |
{ | |
} | |
class Curl implements DataManagement | |
{ | |
private $configs; | |
public function __construct(ConfigManagement $configManagement) | |
{ | |
$this->configs = $configManagement->get(); | |
} | |
public function request() | |
{ | |
/* Some logic to do a request */ | |
} | |
} | |
class Db implements DataManagement | |
{ | |
private $configs; | |
public function __construct(ConfigManagement $configManagement) | |
{ | |
$this->configs = $configManagement->get(); | |
} | |
} | |
class Service | |
{ | |
private $dataManagement; | |
public function __construct(DataManagement $dataManagement) | |
{ | |
$this->dataManagement = $dataManagement; | |
} | |
public function get() | |
{ | |
return $this->dataManagement; | |
} | |
} | |
interface ConfigManagement | |
{ | |
public function get(); | |
} | |
class IniConfig implements ConfigManagement | |
{ | |
public function __construct($file) | |
{ | |
/* Some logic to read configs from file here */ | |
} | |
public function get() | |
{ | |
/* Some logic to return fetched data */ | |
} | |
} | |
$service = new Service( | |
new Curl( | |
new IniConfig('/file/to/config.ini') | |
) | |
); | |
$service->get()->request(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment