OOP, design patterns, frameworks, CMS development and R&D. Research Developer at Tibus / Simply Zesty (2003-2012). Senior Developer at Blue Cube / AV Browne (2013). Senior Developer at 31interactive (2013-present).
first released in July 2011. Very loosely based off Codeigniter. Makes use of several popular and highly tested components such as Symfony's HttpKernel & HttpFoundation, Monolog, Swiftmailer, etc.
a quick, readable way to access Laravel's various components. Big misconception: Laravel is NOT a static framework. Since these facades are syntactic sugar you can bypass them for mocks and tests! You can easily create your own facades or 'rewire' the existing ones.
function index() { ... } public function create() { ... } public function store() { ... } public function show() { ... } public function edit() { ... } public function update() { ... } public function destroy() { ... } }
-> NewsController::create() POST /news -> NewsController::store(); GET /news/{id} -> NewsController::show($id) GET /news/{id}/edit -> NewsController::edit($id) PUT/PATCH /news/{id} -> NewsController::update($id) DELETE /news/{id} -> NewsController::destroy($id) For the previous NewsController route we would have:
Allows you to manipulate a database using object methods calls or using raw SQL. Fluent interface (chainable methods). Clean, English-like syntax. Supports 'complicated' database operations such as joins, aggregates, unions and even caching. Comparable to Zend\Db\Sql, Pear's MDB2 package.
- it has identical syntax! Allows database entities to be mapped to PHP code, commonly referred to as Models. A model definition can be quickly set up using an appropriately named class (no getter/setters required!) Powerful features such as relationships, eager loading, event triggers, accessors/mutators and a lot more! Comparable to Zend\Db\TableGateway, Doctrine, Propel, Redbean.
for rendering your views. Features many of the core functions found in other popular engines such as Twig and Smarty. Since Blade views are PHP scripts, you can use PHP code directly in your templates (with caution!) Inheritance-driven to allow for multiple layouts, sections, etc.
! return View.make('news') ->with('pageTitle', 'News') ->with('posts', $posts); ! }); Assuming that the template on the previous slide is named 'news.blade.php' we can do the following:
component (typically an object) relies on another for its operation. Dependencies should be passed (injected) into an object via its constructor or setter methods and not instantiated inside it. Directly instantiating dependencies is considered bad practise as it reduces scalability and flexibility, plus it makes objects difficult to test in isolation.
{ $this->processor = new Processor\Intel\i7(); } } class Computer { protected $processor; public function __construct(ProcessorInterface $processor) { $this->processor = $processor; } } Bad Good
technique, expressed here in terms of object-oriented programming, in which object coupling is bound at run time by an assembler object and is typically not known at compile time using static analysis." - Wikipedia So... IoC?
Customer(), new DeliveryService\ParcelForce() ); }); The IoC container is a way of automatically passing dependencies into your objects and/or storing them for later retrieval. $shoppingBasket = App::make('shopping_basket');
treat the IoC container as a registry, initialising objects once and returning them on subsequent calls. // First call to App::make() creates the object... $userSession = App::make('user_session'); ! // Second call to App::Make() just fetches it... $sameUserSession = App::make('user_session');
__construct(ProcessorInterface $processor) { $this->processor = $processor; } } If you type-hint the dependencies passed into a constructor then Laravel can do the rest! $computer = App::make('Computer'); // Has i7 processor! App::bind('ProcessorInterface', 'Processor\Intel\i7');
to control Laravel are known as Facades. Facades are nothing more than wrappers to the IoC container. Therefore, every time you use a Facade such as DB, Config, View, Route, etc, you are creating and/or fetching a pre- registered object! You can easily create your own application-specific IoC bindings and Facades.