Download the PHP package orakaro/ioc without Composer
On this page you can find all versions of the php package orakaro/ioc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package ioc
Short Description Tiny IoC module for static mocking in PHP
License MIT
Homepage https://github.com/DTVD/IoC
Informations about the package ioc
Inversion Of Control
"Don't call me let me call you"
- Have you ever heard about Inversion Of Control / Dependency Injection in PHP ?
- Know some giants like Symfony Service Container or Laravel Facades ?
- Wishing you could use Inversion Of Control (IoC) and Facade Design Pattern in your legacy source code ?
I think I can help you a little bit ! Let's start :)
Quick Start
This tiny packge will provide an easy and lightweight way to implement IoC
-
Include following lines in your
composer.json
-
Get classes autoloaded
- Done ! Now head over Usage section !
Usage
Let me assume that you have some class like
Note that method is using class's static method here.
Now let's create another file call IoCRegister.php
Quite simple, right ? Now you can use instead as below
Why I need all that things ?
The idea of IoC help us solve many problem like remove dependencies in codes, remove duplication, etc.. With me it make sense especially in unittesting, where sometimes I have to face with some evil-static-call in classes.
In PHPUnit it's never easy to deal with static methods. Static methods are just death to testability, and PHPUnit have the capablility of mocking static methods where caller and callee are in the same class.
How about when caller and callee in seperated classes ? With IoC implemented, I will help you to overcome that headache in a few basic steps :)
Check out one-minute tutorial !