Fjor, dependency injection container

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
koen.h
Forum Contributor
Posts: 268
Joined: Sat May 03, 2008 8:43 am

Fjor, dependency injection container

Post by koen.h »

I've extracted a dependency injection container from another project and adapted it somewhat so that it could be useful to more people. I don't know if i succeeded so I'm hoping to get some feedback, especially if usage makes sense.

Documentation is here:
https://github.com/koenhoeymans/Fjor/bl ... /index.txt

Or, maybe easier, the end-to-end tests:
https://github.com/koenhoeymans/Fjor/bl ... ocTest.php

An example from these tests. Suppose you have a class that asks for an object implementing ArrayAccess, you can tell Fjor to use an instance of SplObjectStorage, and use the same instance every time it is needed:

Code: Select all

$fjor->given('ArrayAccess')->thenUse('SplObjectStorage')->inSingletonScope();
I think the code makes it clear what it is all about but since I'm not natively english I may be wrong here.
Post Reply