Not everything has been tested yet, use on own risk.
Via Composer
$ composer require mediadevs/response-handlerVia GIT
HTTPS:
git clone https://github.com/mediadevs/response-handler.git
SSH:
git clone git@github.com:mediadevs/response-handler.git<?php
use mikevandiepen\utility\Response;
// Instantiating the Response class
$response = new Response();
// Adding messages and returning a json response
$response->add('Action executed successfully')->toJSON();
?>[
{"level":"primary","message":"Action executed successfully"}
]<?php
use mikevandiepen\utility\Response;
// Instantiating the Response class
$response = new Response();
// Adding messages
$response->add('Action executed successfully', [ /** There must be an array, but can be left empty*/ ], Response::SUCCESS);
// Returning the message in json response
$response->toJSON();
?>[
{"level":"success","message":"Action executed successfully"}
]<?php
use mikevandiepen\utility\Response;
// Instantiating the Response class
$response = new Response();
// Adding messages
$response->add('{%action%} executed {%status%}', ['action' => 'My Custom Action', 'status' => 'successfully'], Response::SUCCESS);
// Returning the message in json response
$response->toJSON();
?>[
{"level":"success","message":"My Custom Action executed successfully"}
]<?php
use mikevandiepen\utility\Response;
// Instantiating the Response class
$response = new Response();
// Adding messages
$response->add('{%action%} executed successfully', ['action' => 'your_action'], Response::SUCCESS);
$response->add('DUPLICATE {%action%}!', ['action' => 'your_action_2'], Response::WARNING);
$response->add('DUPLICATE {%action%}!', ['action' => 'your_action_3'], Response::WARNING);
$response->add('{%action%} does not exist', ['action' => 'your_action_4'], Response::ERROR);
// Returning the messages in json response
$response->toJSON();
?>[
{"level":"success","message":"your_action executed successfully"},
{"level":"warning","message":"DUPLICATE your_action_2!"},
{"level":"warning","message":"DUPLICATE your_action_3!"},
{"level":"danger","message":"your_action_4 does not exist"}
]<?php
use mikevandiepen\utility\Response;
// Instantiating the Response class
$response = new Response();
// Adding messages
$response->add('Look how cool this is! {%parameter%}', ['parameter' => 'Highlight me!'], Response::SUCCESS)->delimiters('"');
// Returning the message in json response
$response->toJSON();
?>[
{"level":"success","message":"Look how cool this is! \"Highlight me!\""}
]In this case we used only one encapsulation string which were applied to both sides. If in your case you want different characters on either side you can add a second item to the array.
For example:
<?php
use mikevandiepen\utility\Response;
// Instantiating the Response class
$response = new Response();
// Adding messages
$response->add('Look how cool this is! {%parameter%}', ['parameter' => 'Highlight me!'], Response::SUCCESS)->delimiters('<strong>', '</strong>');
// Returning the message in json response
$response->toJSON();
?>[
{"level":"success","message":"Look how cool this is! <strong>Highlight me!</strong>"}
]<?php
use mikevandiepen\utility\Response;
// Instantiating the Response class
$response = new Response();
// Adding messages
$response->add('Look how cool this is! {%parameter%}', ['parameter' => 'Highlight me!'], Response::SUCCESS)->delimiters('"');
// Returning the message in json response
$response->toArray();
?>array(
"level" => "success",
"message" => "Look how cool this is! \"Highlight me!\""
);
## Change log
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Testing
``` bash
$ composer test
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email contact@mediadevs.nl instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.


