| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
To implement a loosely coupled architecture in order to get better testable, maintainable and extendable code.
Configuration gets injected and Connection will get all that it needs from $config. Without DI, the configuration would be created directly in Connection, which is not very good for testing and extending Connection.
Notice we are following Inversion of control principle in Connection by asking $config to implement Parameters interface. This decouples our components. We don't care where the source of information comes from, we only care that $config has certain methods to retrieve that information. Read more about Inversion of control here.
You can also find these code on GitHub
AbstractConfig.php
.. literalinclude:: AbstractConfig.php :language: php :linenos:
Parameters.php
.. literalinclude:: Parameters.php :language: php :linenos:
ArrayConfig.php
.. literalinclude:: ArrayConfig.php :language: php :linenos:
Connection.php
.. literalinclude:: Connection.php :language: php :linenos:
Tests/DependencyInjectionTest.php
.. literalinclude:: Tests/DependencyInjectionTest.php :language: php :linenos:
Tests/config.php
.. literalinclude:: Tests/config.php :language: php :linenos:
| Back | FazBrowse Home | New Git URL |