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 146<br />

20<br />

21 $archiver = App::make("ArchiverInterface");<br />

These extra nine lines (using the App::bind() and App::make() methods) tell Laravel 4 how to<br />

find/make new class instances, so we can get to the business of using them!<br />

.<br />

You can learn more about IoC container at: http://laravel.com/docs/ioc.<br />

Service Providers<br />

The main purpose of services providers is to collect and organise the bootstrapping requirements of<br />

your package. They’re not strictly a requirement of package development; but rather a Really Good<br />

Idea.<br />

There are three big things to service providers. The first is that they are registered in a common<br />

configuration array (in app/config/app.php):<br />

1 'providers' => array(<br />

2 'Illuminate\Foundation\Providers\ArtisanServiceProvider',<br />

3 'Illuminate\Auth\AuthServiceProvider',<br />

4 'Illuminate\Cache\CacheServiceProvider',<br />

5 // ...<br />

6 'Illuminate\Validation\ValidationServiceProvider',<br />

7 'Illuminate\View\ViewServiceProvider',<br />

8 'Illuminate\Workbench\WorkbenchServiceProvider',<br />

9 ),<br />

.<br />

This was extracted from app/config/app.php.<br />

You can also add your own service providers to this list; as many packages will recommend you do.<br />

There there’s the register() method:

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

Saved successfully!

Ooh no, something went wrong!