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.

File-Based CMS 311<br />

25 "Formativ\Cms\EngineInterface",<br />

26 "Formativ\Cms\Engine\Blade"<br />

27 );<br />

28 }<br />

29<br />

30 public function provides()<br />

31 {<br />

32 return [<br />

33 "Formativ\Cms\CompilerInterface",<br />

34 "Formativ\Cms\EngineInterface"<br />

35 ];<br />

36 }<br />

37 }<br />

This file should be saved as workbench/formativ/cms/src/Formativ/Cms/CmsServiceProvider.php.<br />

.<br />

The CompilerBlade class encapsulates the BladeCompiler class, allowing us to implement the<br />

CompilerInterface interface. This is a way of future-proofing our package so that the code which<br />

depends on methods Blade currently implements won’t fail if future versions of Blade were to<br />

remove that implementation.<br />

.<br />

We’ll also be adding additional template tags in via this class, so it’s not all overhead.<br />

The EngineBlade class contains the method which we will use to render template strings. It<br />

implements the EngineInterface interface for that same future-proofing.<br />

We register all of these in the CmsServiceProvider. We can now inject these dependencies in our<br />

controller:

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

Saved successfully!

Ooh no, something went wrong!