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

Packages are the recommended way of extending the functionality provided by Laravel 4. They’re<br />

nothing more than Composer libraries with some particular bootstrapping code.<br />

.<br />

The code for this chapter can be found at: https://github.com/formativ/tutorial-laravel-4-<br />

packages<br />

This chapter follows on from a previous chapter which covered the basics of creating a deployment<br />

process for your applications. It goes into detail about creating a Laravel 4 installation; so you should<br />

be familiar with it before spending a great deal of time in this one. You’ll also find the source-code<br />

we created there to be a good basis for understanding the source code of this chapter.<br />

I learned the really technical bits of this chapter from reading Taylor’s book. If you take away just<br />

one thing from this it should be to get and read it.<br />

Composer<br />

While the previous chapter shows you how to create a Laravel 4 project; we need to do a bit more<br />

work in this area if we are to understand one of the fundamental ways in which packages differ<br />

from application code.<br />

Laravel 3 had the concept of bundles; which were downloadable folders of source code. Laravel<br />

4 extends this idea, but instead of rolling its own download process, it makes use of Composer.<br />

Composer should not only be used to create new Laravel 4 installations; but also as a means of<br />

adding packages to existing Laravel 4 applications.<br />

Laravel 4 packages are essentially the same things as normal Composer libraries. They often utilise<br />

functionality built into the Laravel 4 framework, but this isn’t a requirement of packages in general.<br />

It follows that the end result of our work today is a stand-alone Composer library including the<br />

various deployment tools we created last time. For now, we will be placing the package code inside<br />

our application folder to speed up iteration time.<br />

Dependency Injection<br />

One of the darlings of modern PHP development is Dependency Injection. PHP developers have<br />

recently grown fond of unit testing and class decoupling. I’ll explain both of these things shortly;<br />

but it’s important to know that they are greatly improved by the use of dependency injection.

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

Saved successfully!

Ooh no, something went wrong!