2017 © Pedro Peláez
 

library response

a package that allows you to have a boostrap similar rest response object

image

sircamp/response

a package that allows you to have a boostrap similar rest response object

  • Thursday, September 3, 2015
  • by sircamp
  • Repository
  • 1 Watchers
  • 1 Stars
  • 27 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Sircamp Response

This package allows you to have a "Boostrap-like" rest response object using an Alert like: Info, Warning, Error, Success., (*1)

With this package you only return the right response object to your views or your REST response, you can set the correct type of Boostrap alert without any IF statement. Also, on each response object that you create, you can set a message a data payload with all your data., (*2)

INSTALLATION

In your root project's directory type:, (*3)

composer require sircamp/response

According to your composer.json, you obtain the right version (stable or dev), (*4)

USAGE

In each file where you are using one of the Sircamp\Response objects you must add the right namespace., (*5)

use Sircamp\Response\InfoResponse as InfoResponse;
use Sircamp\Response\WarningResponse as WarningResponse;
use Sircamp\Response\SuccessResponse as SuccessResponse;
use Sircamp\Response\DangerResponse as DangerResponse;

new Response

To create new Response object ( InfoResponse for example ) you need two parameters., (*6)

A String message, that could be empty, and an array named data., (*7)

The data array could contain everthing you want, object, string and much more., (*8)

Pay attention that each type of object has automatically set the type string parameter:, (*9)

  • In case of InfoResponse the type attribute is setted to info
  • In case of WarningResponse the type attribute is setted to warning
  • In case of SuccessResponse the type attribute is setted to success
  • In case of DangerResponse the type attribute is setted to danger

$data = [ 'object' => new Object('example'), 'number' => 1, 'string' => "hello world" //etc ]; $message = "I want to say hello world"; $infoResponse = new InfoResponse($data,$message);

getType

This method returns the type of object's istance, (*10)


$infoResponse->getType();

setType

This method sets the type of the object, (*11)


$infoResponse->setType($type);

getMessage

This method returns the message attribute of of the object, (*12)


$infoResponse->getMessage();

setMessage

This method sets the message attribute of of the object, (*13)

$message = "I want to say hello world";
$infoResponse->setMessage($message);

getData

This method returns the data attribute of of the object, (*14)


$infoResponse->getData();

setData

This method sets the data attribute of of the object. As seed the $data parameters is an associative array that contains a mixin of variable, (*15)

$data = [
    'object' => new Object('example'),
    'number' => 1,
    'string' => "hello world"
    //etc
];
$infoResponse->setData($data);

addAllowedType

This method is a static method that allows you to add a castum response type. If you add a custom type, you can create a new extended custom class ( with your desidered type ) at runtime., (*16)

To create an anonymous runtime class you must have PHP 7, (*17)

$type = "custom";
BaseResponse::addAllowedType($type);

The Versions

03/09 2015

dev-master

9999999-dev

a package that allows you to have a boostrap similar rest response object

  Sources   Download

MIT

The Requires

 

by Avatar sircamp

laravel json rest bootstrap symfony response

03/09 2015

dev-develop

dev-develop

a package that allows you to have a boostrap similar rest response object

  Sources   Download

MIT

The Requires

 

by Avatar sircamp

laravel json rest bootstrap symfony response

03/09 2015

1.5

1.5.0.0

a package that allows you to have a boostrap similar rest response object

  Sources   Download

MIT

The Requires

 

by Avatar sircamp

laravel json rest bootstrap symfony response

11/08 2015

1.4

1.4.0.0

a package that allows you to have a boostrap similar rest response object

  Sources   Download

MIT

The Requires

 

by Avatar sircamp

11/08 2015

1.3

1.3.0.0

a package that allows you to have a boostrap similar rest response object

  Sources   Download

MIT

The Requires

 

by Avatar sircamp

11/08 2015

1.2

1.2.0.0

a package that allows you to have a boostrap similar rest response object

  Sources   Download

MIT

The Requires

 

by Avatar sircamp

11/08 2015

1.1

1.1.0.0

a package that allows you to have a boostrap similar rest response object

  Sources   Download

MIT

The Requires

 

by Avatar sircamp

11/08 2015

v1.0

1.0.0.0

a package that allows you to have a boostrap similar rest response object

  Sources   Download

MIT

The Requires

 

by Avatar sircamp

11/08 2015

1.0

1.0.0.0

a package that allows you to have a boostrap similar rest response object

  Sources   Download

MIT

The Requires

 

by Avatar sircamp