PHP code example of anax / response

1. Go to this page and download the library: Download anax/response 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/ */

    

anax / response example snippets


/**
 * Configuration file for DI container.
 */
return [
    // Services to add to the container.
    "services" => [
        "response" => [
            "shared" => true,
            //"callback" => "\Anax\Response\Response",
            "callback" => function () {
                $obj = new \Anax\Response\ResponseUtility();
                $obj->setDI($this);
                return $obj;
            }
        ],
    ],
];

// Leave to router to match incoming request to routes
$response = $di->get("router")->handle(
    $di->get("request")->getRoute(),
    $di->get("request")->getMethod()
);
// Send the HTTP response with headers and body
$di->get("response")->send($response);

# $app style
$app->response->redirectSelf();

# $di style, two alternatives
$di->get("response")->redirectSelf();

$response = $di->get("response");
$response->redirectSelf();

# Create an object
response = new \Anax\Response\Response();

# Send a response
response->send("Some response");
response->sendJson(["key" => "Some value"]);
response->redirect($absoluteUrl);

# Create an object
response = new \Anax\Response\ResponseUtility();

# Do a redirect
response->redirect("game/init");
response->redirectSelf();