Dependency Injection with PHP
       Nikita Groshin
     Nguyễn Huy Tuấn
Itim

    More than 200 employees

    More than 80 developers from different
    countries

    Different programming languages and
    paradigm

    Java, C++, PHP, JS, Python etc
Frontend and Tools Deprtment

    13 members

    PHP, JS, Python

    Kohana, Zend Framework

    100% Zend Certificated developers
Core Products

    Search engine http://coccoc.vn/

    Browser http://corom.vn

    Not only
"Developers! Developers!
       Developers"




"Dependency! Dependency!
      Dependency"
Dependencies are suck?





    NO. They are useful!

    Hard code is suck
Good Dependency
Bad Dependency
Bad
Better
Good
Dependency Injection are simple.
Bad
Good
Injection types

    Constructor injection

    Setter injection

    Interface injection
Interface Injection
Interface injection
Quite easy.
But why to use it?
Hard coded dependency

    Hard to reuse

    Poor isolation

    Hard to test

    A lot of code

    Hard to maintain

    Hard to understand
Dependency injection

    Loose coupling

    Reuse of code

    Reduce amount of code

    Clear and Understandable

    Extremely easy to test
Dependency injection

    Loose coupling

    Reuse of code

    Reduce amount of code

    Clear and Understandable


    Extremely easy to test
Extremely easy to test
Manual Di management is
     complicated.
We need container!
Disclaimer

    Dependency Injection != DI container

    DI container use Service Locator Anti-Pattern

    DI container make code 'less native'

    Powerful tool – use careful

    Often Manual injection is enough
How many lines of code
 we need for simple
    DI container?
Twittee

    http://twittee.org/

     Packed in less than 140 characters, it fits in a
    tweet.

    Author Fabien Potencier

    Production ready
Twittee source
Pimple

    http://pimple.sensiolabs.org/

    50 lines of code

    Full functionality

    Author Fabien Potencier

    Production ready
Questions?

    job.coccoc.vn

    nike-17@coccoc.vn

Dependency injection with PHP