2017 © Pedro Peláez
 

library response

Anax Response module.

image

anax/response

Anax Response module.

  • Monday, October 16, 2017
  • by mikael_roos
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3,640 Installations
  • PHP
  • 25 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 11 % Grown

The README.md

Anax Response

Latest Stable Version Join the chat at https://gitter.im/mosbth/anax, (*1)

Build Status CircleCI, (*2)

Build Status Scrutinizer Code Quality Code Coverage, (*3)

Maintainability Codacy Badge, (*4)

Anax Response module to send HTTP responses., (*5)

The module is used to send a HTTP response from the Anax framework, including status code, headers, and body., (*6)

Table of content

Class, interface, trait

The following classes, interfaces and traits exists., (*7)

Class, interface, trait Description
Anax\Response\Response Wrapper class for response details and related.
Anax\Response\ResponseUtility Extends the Request class to be injectable with $id to enable easy to use redirect methods.

Exceptions

Module specific exceptions are thrown through Anax\Response\Exception., (*8)

Configuration file

There is no configuration file for this module., (*9)

DI service

The module is created as a framework service within $di. You can see the details in the configuration file config/di/response.php., (*10)

It can look like this., (*11)

/**
 * 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;
            }
        ],
    ],
];
  1. The object is created as a shared resource.
  2. DI is injected into the module, when using ResponseUtility.

The service is lazy loaded and not created until it is used., (*12)

General usage within the Anax framework

The response service is a mandatory service within the Anax framework and it is the first service used when handling a request to the framework., (*13)

Here is the general flow for receiving a request, mapping it to a route and returning a response. This is found in the frontcontroller htdocs/index.php of an Anax installation., (*14)

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

The request is used to get the request method and the route path, these are used by the router service to find a callback for the route. Each callback can then return a response which is sent through the response service., (*15)

Access as framework service

You can access the module as a framework service., (*16)

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

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

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

Create, init and use an object

This is how the object can be created. This is usually done within the framework as a sevice in $di., (*17)

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

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

The added benefit of using ResponseUtility is that this class is injected with DI and makes it easier to use the redirect methods for urls within the framework., (*18)

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

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

License

This software carries a MIT license. See LICENSE.txt for details., (*19)

 .  
..:  Copyright (c) 2013 - 2019 Mikael Roos, mos@dbwebb.se

The Versions

16/10 2017

dev-master

9999999-dev https://dbwebb.se/anax

Anax Response module.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • php >=5.6

micro framework boilerplate mvc education

16/10 2017

v1.0.8

1.0.8.0 https://dbwebb.se/anax

Anax Response module.

  Sources   Download

MIT

The Requires

 

micro framework boilerplate mvc education

11/09 2017

v1.0.7

1.0.7.0 https://dbwebb.se/anax

Anax Response module.

  Sources   Download

MIT

The Requires

 

micro framework boilerplate mvc education

17/08 2017

v1.0.6

1.0.6.0 https://dbwebb.se/anax

Anax Response module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

micro framework boilerplate mvc education

12/04 2017

v1.0.5

1.0.5.0 https://dbwebb.se/anax

Anax Response module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

micro framework boilerplate mvc education

13/03 2017

v1.0.4

1.0.4.0 https://dbwebb.se/anax

Anax Response module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

  • php >=5.6

micro framework boilerplate mvc education

10/03 2017

v1.0.3

1.0.3.0 https://dbwebb.se/anax

Anax Response module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

  • php >=5.6

micro framework boilerplate mvc education

09/03 2017

v1.0.2

1.0.2.0 https://dbwebb.se/anax

Anax Response module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

  • php >=5.6

micro framework boilerplate mvc education

07/03 2017

v1.0.1

1.0.1.0 https://dbwebb.se/anax

Anax Response module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

  • php >=5.6

micro framework boilerplate mvc education

07/03 2017

v1.0.0

1.0.0.0 https://dbwebb.se/anax

Anax Response module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

  • php >=5.6

micro framework boilerplate mvc education