2017 © Pedro Peláez
 

library cbor4laravel

CBOR provider for Laravel.

image

lrezek/cbor4laravel

CBOR provider for Laravel.

  • Friday, January 9, 2015
  • by lrezek
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

About

Cbor4Laravel adds CBOR functionality to Laravel Requests and Responses. For more information on what CBOR is, please see the spec., (*1)

Installation

Add lrezek/cbor4laravel as a requirement to composer.json:, (*2)

{
    "require": {
       "lrezek/cbor4laravel": "dev-master"
    }
}

Depending on your stability settings, you may also need to add a requirement to "lemonblast/cbor4php": "dev-master"., (*3)

Update your packages with composer update or install with composer install., (*4)

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:, (*5)

use Illuminate\Foundation\Application;

Application::requestClass('LRezek\Cbor4Laravel\Http\Request');

This enables the following 3 methods:, (*6)


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., (*7)

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:, (*8)

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:, (*9)

  //'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., (*10)

Additionally, you can make a custom response and format it in CBOR as follows:, (*11)

Response::make($content)->format('cbor'); //Returns a CBOR formatted Response.

The Versions

09/01 2015

dev-master

9999999-dev https://github.com/lrezek/Cbor4Laravel

CBOR provider for Laravel.

  Sources   Download

MIT

The Requires

 

by Adam Weber

laravel cbor