v1.0.1 2020-01-24 21:58 UTC

This package is not auto-updated.

Last update: 2020-02-07 22:15:23 UTC


README

Description

Library contains HTTP components, to use features and other libraries components, on HTTP context.

Requirement

  • Script language: PHP: version 5.6 || 7

Installation

Several ways are possible:

Composer, by command line

  1. Command: Move in project root path

     cd "<project_root_path>"
    
  2. Command: Installation

     php composer.phar require --prefer-dist liberty_code/http ["<version>"]
    

Composer, by "composer.json"

  1. Command: Move in project root path

     cd "<project_root_path>"
    
  2. Configuration: composer: "/composer.json"

    Add in require part, repository configuration:

     {
         "require": {
             "liberty_code/http": "<version>"
         }
     }
    
  3. Command: Update

     php composer.phar update
    

Include

  1. Include file: /include/Include.php

     require_once('<repository_root_path>/include/Include.php');
    

Configuration

Main configuration

  • Use following class to configure specific elements

      use liberty_code\http\config\model\DefaultConfig;
      DefaultConfig::instanceGetDefault()->get|set...();
    
  • Elements configurables

    • Route options
    • Request options
    • Response options

Usage

Register

Register using specific HTTP data storage as storage support.

Elements

  • SessionRegister

    Extends table register features. Allows to manage items, using session as array of items.

  • CookieRegister

    Extends table register features. Allows to manage items, using cookie as array of items. Uses PHP serialization encoding for items storing, on cookie.

  • JsonCookieRegister

    Extends cookie register features. Uses JSON encoding for items storing, on cookie.

Example

...
// Get register
use liberty_code\http\register\session\model\SessionRegister;
$register = SessionRegister::instanceGetDefault();
...
$register->putItem('key_1', '...'); // Register specified item for key 1
$register->putItem('key_N', '...'); // Register specified item for key N
...
foreach($register->getTabKey() as $key) {
    var_dump($register->getItem($key));
}
/**
 * Show: 
 * item for key 1
 * item for key N
 */
...

Route

Route allows to interpret specified source, from http request, on HTTP context, to get executable.

Elements

  • HttpPatternRoute, HttpParamRoute, HttpFixRoute, HttpSeparatorRoute

    Extends route features. Adapt all standard routes, to interpret specified source, from HTTP request.

  • HttpRouteFactory

    Extends DI route factory features. Provides HTTP route instance.

Request

Request allows to provide route source, on request flow process and HTTP context.

Elements

  • HttpRequest

    Extends request features. Allows to design HTTP request.

Example

class HttpRequestTest extends liberty_code\http\request_flow\request\model\HttpRequest
{
    // Define rules to get route source
    public function getStrRoute()
    {
        // Get route source from GET "route" argument
        return $this->getGet('route', 'N/A');
    }
}

$request = HttpRequestTest::instanceGetDefault();
echo($request->getStrRouteSrc()); // Show "<HTTP method>:<route>"
...

Response

Response allows to provide final send-able content, from request flow process, on HTTP context.

Elements

  • HttpResponse

    Extends response features. Allows to design HTTP response, with adequate contents to send.

  • RedirectResponse

    Extends HTTP response features. Allows to design HTTP redirection response, with adequate contents to send.

  • Response utilities

    Parsed content response allows to get response with specific formatted content, on HTTP context. Example: HTTP JSON response, HTTP XML response, etc...

Example

use liberty_code\http\request_flow\response\model\HttpResponse;
$objResponse = new HttpResponse();
$objResponse->setContent(...);
...

Front controller

Front controller allows to design the request flow process, on HTTP context.

Elements

  • HttpFrontController

    Extends front controller features. Uses HTTP request, to get HTTP response.

Example

use liberty_code\http\request_flow\front\model\HttpFrontController;
$frontController = new HttpFrontController();
$frontController->setRouter(...);
$frontController->setActiveRequest(...);
...
// Show response object
var_dump($frontController->execute());
...

Authentication

Authentication allows to design an authentication class, using HTTP request arguments.

Elements

  • HttpAuthentication

    Extends authentication features. Uses HTTP request arguments, to get all identification and authentication information.

Example

// Get HTTP authentication
use liberty_code\http\authentication\authentication\model\HttpAuthentication
$httpAuth = new HttpAuthentication($request);
$httpAuth->setAuthConfig(...);
...
// Get array of identification data
var_dump($httpAuth->getTabIdData());
...
// Get array of authentication data
var_dump($httpAuth->getTabAuthData());
...