From 454382d8fbf72b691e02cb129118962037a218be Mon Sep 17 00:00:00 2001 From: Dominik Liebler Date: Wed, 11 Sep 2013 16:21:26 +0200 Subject: [PATCH] cs DependencyInjection --- ...endencyInjection.php => Configuration.php} | 36 +++++-------------- DependencyInjection/Connection.php | 35 ++++++++++++++++++ 2 files changed, 44 insertions(+), 27 deletions(-) rename DependencyInjection/{DependencyInjection.php => Configuration.php} (57%) create mode 100644 DependencyInjection/Connection.php diff --git a/DependencyInjection/DependencyInjection.php b/DependencyInjection/Configuration.php similarity index 57% rename from DependencyInjection/DependencyInjection.php rename to DependencyInjection/Configuration.php index e4693e9..f972bb6 100644 --- a/DependencyInjection/DependencyInjection.php +++ b/DependencyInjection/Configuration.php @@ -1,6 +1,6 @@ _host = $host; + $this->host = $host; + return $this; // for a fluent interface } @@ -35,29 +40,6 @@ class Configuration */ 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(); - // ... + return $this->host; } } diff --git a/DependencyInjection/Connection.php b/DependencyInjection/Connection.php new file mode 100644 index 0000000..02ff81b --- /dev/null +++ b/DependencyInjection/Connection.php @@ -0,0 +1,35 @@ +configuration = $config; + } + + /** + * connection using the injected config + */ + public function connect() + { + $host = $this->configuration->getHost(); + // ... + } +}