webino/request

Simple PHP environment request implementation.

dev-develop 2019-07-19 22:13 UTC

This package is auto-updated.

Last update: 2024-10-20 10:19:04 UTC


README

Simple PHP environment request implementation. [WIP]

Build Status Coverage Status Code Quality Latest Stable Version

Recommended Usage

Request data for application dispatch.

Setup

PHP from Packagist

composer require webino\request

Quick Use

Getting request object for current execution context:

use Webino\InstanceContainer;
use Webino\HttpRequest;
use Webino\ConsoleRequest;
use Webino\RequestInterface;

$container = new InstanceContainer;

/** @var RequestInterface $request */
$request = $container->get(RequestInterface::class);

if ($request instanceof HttpRequest) {

} elseif ($request instanceof ConsoleRequest) {

}

Making HTTP request:

use Webino\InstanceContainer;
use Webino\HttpRequest;

$container = new InstanceContainer;

/** @var HttpRequest $request */
$request = $container->make(HttpRequest::class, HttpRequest::defaults([
    HttpRequest::QUERY_STRING => 'foo=bar&baz=bam',
    HttpRequest::SCRIPT_NAME => '/example/index.php',
    HttpRequest::SCRIPT_FILENAME => '/var/www/html/example/index.php',
    HttpRequest::URI => '/example/some-route'
]));

Making console request:

use Webino\InstanceContainer;
use Webino\ConsoleRequest;

$container = new InstanceContainer;

/** @var ConsoleRequest $request */
$request = $container->make(ConsoleRequest::class, ConsoleRequest::defaults([
    ConsoleRequest::COMMAND => 'foo --bar baz',
    ConsoleRequest::SCRIPT_FILENAME => '/var/www/html/test/index.php',
]));

API

RequestInterface

  • const TIME
    Request time float option.

  • const TIME_DEFAULT
    Default request time float, example value.

  • const SCRIPT_FILENAME
    Executed script file name string option.

  • const SCRIPT_FILENAME_DEFAULT
    Default executed script file name, example value.

  • float getRequestTime()
    Returns HTTP request time.

  • string getScriptFileName()
    Returns executed script file name.

HttpRequest

  • const SCRIPT_NAME
    Executed script name string option.

  • const SCRIPT_NAME_DEFAULT
    Executed script name, example value.

  • const GATEWAY_INTERFACE
    Gateway interface string option.

  • const GATEWAY_INTERFACE_DEFAULT
    Gateway interface, example value.

  • const SERVER_SOFTWARE
    Server software string option.

  • const SERVER_SOFTWARE_APACHE
    Apache server software, example value.

  • const SERVER_SOFTWARE_NGINX
    Nginx server software, example value.

  • const HOST
    Server host name string option.

  • const HOST_LOCAL
    Local server host name, example value.

  • const HOST_IP
    Server IP address string option.

  • const HOST_IP_LOCAL
    Local server IP address, example value.

  • const URI
    Request URI string option.

  • const URI_DEFAULT
    Request URI, example value.

  • const METHOD
    Request method string option.

  • const METHOD_GET
    GET request method, example value.

  • const METHOD_POST
    POST request method, example value.

  • const SCHEME
    Request scheme string option.

  • const SCHEME_HTTP
    HTTP request scheme, example value.

  • const SCHEME_HTTPS
    HTTPS request scheme, example value.

  • const PORT
    Request port string option.

  • const PORT_HTTP
    HTTP request port, example value.

  • const PORT_HTTPS
    HTTPS request port, example value.

  • const QUERY_STRING
    Query string option.

  • const QUERY_STRING_DEFAULT
    Query string, example value.

  • const ACCEPT
    Accept header string option.

  • const ACCEPT_HTML
    Accept HTML header, example value.

  • const ACCEPT_LANGUAGE
    Accept language header string option.

  • const ACCEPT_LANGUAGE_DEFAULT
    Default accept language, example value.

  • const ACCEPT_CHARSET
    Accept charset header string option.

  • const ACCEPT_CHARSET_DEFAULT
    Default charset header, example value.

  • const ACCEPT_ENCODING
    Accept encoding header string option.

  • const ACCEPT_ENCODING_DEFAULT
    Default accept encoding header, example value.

  • const USER_AGENT
    User agent header string option.

  • const USER_AGENT_DEFAULT
    Default user agent header, example value.

  • const REFERER
    Referer header string option.

  • const REFERER_DEFAULT
    Default referer header, example value.

  • const REMOTE_IP
    Remote IP address string option.

  • const REMOTE_IP_LOCAL
    Local remote IP address, example value.

  • const REMOTE_PORT
    Remote port string option.

  • const REMOTE_PORT_DEFAULT
    Default remote port, example value.

  • const REQUESTED_WITH
    The x-requested-with header string option.

  • const REQUESTED_WITH_AJAX
    The Ajax x-requested-with header, example value.

  • string getRoutePath()
    Returns route path.

  • string getScriptName()
    Returns executed script name.

  • string getMethod()
    Returns HTTP request method.

  • string getHost()
    Returns HTTP host name.

  • string getHostIP()
    Returns HTTP host IP address.

  • string getScheme()
    Returns HTTP request scheme.

  • bool isHttps()
    Returns true when request scheme is HTTPS.

  • string getPort()
    Returns HTTP request port.

  • string getQueryString()
    Returns HTTP request query string.

  • string getBasePath()
    Returns HTTP root.

  • string getUri()
    Returns request URI.

  • string getGatewayInterface()
    Returns server gateway interface identifier.

  • string getServerSoftware()
    Returns server software identifier.

  • string getAccept()
    Returns HTTP accept header value.

  • string getAcceptLanguage()
    Returns HTTP accept language header value.

  • string getAcceptCharset()
    Returns HTTP accept charset header value.

  • string getAcceptEncoding()
    Returns HTTP accept encoding header value.

  • string getUserAgent()
    Returns HTTP request user agent.

  • string getReferer()
    Returns HTTP referer header value.

  • string getRemoteIP()
    Returns HTTP remote IP address.

  • string getRemotePort()
    Returns HTTP remote port.

  • bool isAjax()
    Returns true when request was made by Ajax.

  • array static defaults(array $overrides = [])
    Returns default HTTP request options, example values.

ConsoleRequest

  • const COMMAND
    Console command string option.

  • string getCommand()
    Returns console command.

  • array static defaults(array $overrides = [])
    Returns default console request options, example values.

Development

Build Status Coverage Status Code Quality Latest Unstable Version

Static analysis:

composer analyse

Coding style check:

composer check

Coding style fix:

composer fix

Testing:

composer test

Git pre-commit setup:

ln -s ../../pre-commit .git/hooks/pre-commit

Addendum

License Total Downloads GitHub code size in bytes

Please, if you are interested in this library report any issues and don't hesitate to contribute. We will appreciate any contributions on development of this library.

GitHub issues GitHub forks