SitePoint Sponsor

User Tag List

Results 1 to 25 of 39

Threaded View

  1. #1
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    The smallest dependency injector?

    Hi.

    As a result of an article for PHP|Architect I have finally gotten a chance to play with dependency injection and the result is called "Phemto". It's the bare minimum of a dependency injector as I understand it. I am sure that I have missed some vital feature that Jason, et al. will tell me about. It only works with PHP5.

    Here is a sample piece of usage...
    PHP Code:
    class Datacash implements PaymentGateway { ... }

    class 
    PayementInAdvance implements SignUpProcess {
        function 
    __construct(PaymentGateway $gateway) { ... }
        ...
    }

    $injector = new Injector();
    $injector->register('Datacash');
    $injector->register('PaymentInAdvance');

    $sign_up $injector->create('SignUpProcess'); 
    That is the wiring can be done purely by interfaces and is handled by typed constructors. As usual when I post code on the forum, it's a plaything that anyone is welcome to carry forward. Idon't advise using it in the real world though .

    yours, Marcus
    Attached Files Attached Files
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •