diff --git a/DependenyInjection/DependencyInjection.php b/DependenyInjection/DependencyInjection.php new file mode 100644 index 0000000..896527c --- /dev/null +++ b/DependenyInjection/DependencyInjection.php @@ -0,0 +1,63 @@ +_host = $host; + return $this; // for a fluent interface + } + + /** + * @return string + */ + public function getHost() + { + return $this->_host; + } +} + +class Connection +{ + 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; + } + + public function connect() + { + $host = $this->_configuration->getHost(); + // ... + } +} \ No newline at end of file