Skip to content

Instantly share code, notes, and snippets.

@ogabrielsantos
Created February 15, 2015 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogabrielsantos/c75ad3baae407257d29b to your computer and use it in GitHub Desktop.
Save ogabrielsantos/c75ad3baae407257d29b to your computer and use it in GitHub Desktop.
<?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