03.12.2015 Views

laravel4cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Packages 145<br />

35 class Archiver implements ArchiverInterface<br />

36 {<br />

37 protected $provider;<br />

38<br />

39 public function __construct(<br />

40 EntryProviderInterface $provider<br />

41 )<br />

42 {<br />

43 $this->provider = $provider;<br />

44 }<br />

45<br />

46 // ...<br />

47 }<br />

48<br />

49 $database = new Database();<br />

50 $provider = new EntryProvider($database);<br />

51 $archiver = new Archiver($provider);<br />

This shallowly represents a dependency (injection) chain. The last three lines are where the problem<br />

starts to become clear; the more we abstract our dependencies, the more “bootstrapping” code needs<br />

to be done every time we need the Archiver class.<br />

We could abstract this by using Laravel 4’s IoC container:<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!