cs DependencyInjection

This commit is contained in:
Dominik Liebler
2013-09-11 16:21:26 +02:00
parent 79f94ba501
commit 454382d8fb
2 changed files with 44 additions and 27 deletions

View File

@@ -0,0 +1,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();
// ...
}
}