Package Data | |
---|---|
Maintainer Username: | lrezek |
Maintainer Contact: | lukas@miratronix.com (Lukas Rezek) |
Package Create Date: | 2014-09-15 |
Package Last Update: | 2015-01-09 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-19 03:20:33 |
Package Statistics | |
---|---|
Total Downloads: | 17 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
#About Cbor4Laravel adds CBOR functionality to Laravel Requests and Responses. For more information on what CBOR is, please see the spec.
#Installation
Add lrezek/cbor4laravel
as a requirement to composer.json
:
{
"require": {
"lrezek/cbor4laravel": "dev-master"
}
}
Depending on your stability settings, you may also need to add a requirement to "lemonblast/cbor4php": "dev-master"
.
Update your packages with composer update
or install with composer install
.
##Request
Because the Request class is made so early in the Laravel lifecycle, you need to override the implementation in bootstrap/start.php
. Add the following to the start of the file:
use Illuminate\Foundation\Application;
Application::requestClass('LRezek\Cbor4Laravel\Http\Request');
This enables the following 3 methods:
Request::isCbor(); //Returns true if the request is in CBOR format, false otherwise.
Request::wantsCbor(); //Returns true if the accept type of the request is CBOR, false otherwise.
Request::cbor(); //Returns the decoded request content.
Please note that all three of these methods are also available in the Input
Facade, as Input
and Request
are the same object in Laravel.
As with Input::json()
, Input::cbor()
allows you to get CBOR decoded data in a ParameterBag
. This means you can specify a key and a default value to get, or get all the input as an array:
Input::cbor()->all(); //Get all input as an array.
Input::cbor($key); //Get value of the specified key in the input.
Input::cbor($key, $default); //Get value of specified key in the input, or the specified $default if the key isn't found.
##Response
To enable CBOR responses, simply replace Laravel's Response
Facade in the aliases
array of app/config/app.php
:
//'Response' => 'Illuminate\Support\Facades\Response',
'Response' => 'LRezek\Cbor4Laravel\Facades\Response',
This allows you to use Response::cbor()
the same way you would use Response::json()
. For an example of this, please refer to the Laravel documentation.
Additionally, you can make a custom response and format it in CBOR as follows:
Response::make($content)->format('cbor'); //Returns a CBOR formatted Response.