03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Packages 148<br />

with the IoC container (which App extends). If you need to do other bootstrapping stuff then the<br />

method you need to use is boot():<br />

1 public function boot()<br />

2 {<br />

3 Model::setConnectionResolver($this->app['db']);<br />

4 Model::setEventDispatcher($this->app['events']);<br />

5 }<br />

This was extracted from vendor/laravel/framework/src/Illuminate/Database/DatabaseServiceProvider.php.<br />

.<br />

This boot() method sets two properties on the Model class. The same class also has a register method<br />

but these two settings are pet for the boot method.<br />

You can learn more about service providers at: http://laravel.com/docs/packages#service-providers.<br />

.<br />

Organising Code<br />

Now that we have some tools to help us create packages; we need to port our code over from being<br />

application code to being a package. Laravel 4 provides a useful method for creating some structure<br />

to our package:<br />

1 php artisan workbench Formativ/Deployment<br />

You’ll notice a new folder has been created, called workbench. Within this folder you’ll find an<br />

assortment of files arranged in a similar way to those in the vendor/laravel/framework/src/Illuminate/*<br />

folders.<br />

We need to break all of the business logic (regarding deployment) into individual classes, making<br />

use of the IoC container and dependency injection, and make a public API.<br />

.<br />

We’re not going to spend a lot of time discussing the intricacies of the deployment classes/scripts<br />

we made in the last tutorial. Refer to it if you want more of those details.

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

Saved successfully!

Ooh no, something went wrong!