### **Request Extension** ###
Because it is such a foundational piece of the framework and is instantiated very early in the request cycle, extending the ``Request`` class works a little differently than the previous examples.
First, extend the class like normal:
~~~
<!-- lang:php -->
namespace QuickBill\Extensions;
class Request extends \Illuminate\Http\Request {
// Custom, helpful methods here...
}
~~~
Once you have extended the class, open the ``bootstrap/start.php`` file. This file is one of the very first files to be included on each request to your application. Note that the first action performed is the creation of the Laravel ``$app`` instance:
~~~
<!-- lang:php -->
$app = new \Illuminate\Foundation\Application;
~~~
When a new application instance is created, it will create a new ``Illuminate\Http\Request`` instance and bind it to the IoC container using the ``request`` key. So, we need a way to specify a custom class that should be used as the "default" request type, right? And, thankfully, the ``requestClass`` method on the application instance does just this! So, we can add this line at the very top of ``our bootstrap/start.php`` file:
~~~
<!-- lang:php -->
use Illuminate\Foundation\Application;
Application::requestClass('QuickBill\Extensions\Request');
~~~
Once you have specified the custom request class, Laravel will use this class anytime it creates a ``Request`` instance, conveniently allowing you to always have an instance of your custom request class available, even in unit test!
- Dependency Injection
- The Problem
- Build A Contract
- Take It further
- Too Much Java?
- The IoC Container
- Basic Binding
- Reflective Resolution
- Interface As Contract
- Strong Typing & Water Fowl
- A Contract Example
- Interface & Team Development
- Service Provider
- As Bootstrapper
- As Organizer
- Booting Providers
- Providing The Core
- Application Structure
- MVC Is Killing You
- Bye, Bye Models
- It's All About The Layers
- Where To Put "Stuff"
- Applied Architecture: Decoupling Handles
- Decoupling Handlers
- Other Handlers
- Extending The Framework
- Manager & Factories
- Cache
- Session
- Authentication
- IoC Based Extension
- Request Extension
- Single Responsibility Principle
- Open Closed Principle