PHP code example of mediadevs / response-handler

1. Go to this page and download the library: Download mediadevs/response-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mediadevs / response-handler example snippets



use mikevandiepen\utility\Response;

// Instantiating the Response class
$response = new Response();

// Adding messages and returning a json response
$response->add('Action executed successfully')->toJSON();


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();


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();


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();


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();


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();


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!\""
);