cse/helpers-request

The helpers allows you to Request processing. Get value for POST/GET/REQUEST method by key and set default value, check exist AJAX, POST and GET method - all this is available in this library.

1.0.6 2019-04-29 04:09 UTC

This package is auto-updated.

Last update: 2024-11-29 05:39:11 UTC


README

English | Русский

REQUEST CSE HELPERS

Travis (.org) Codecov Scrutinizer code quality

Packagist Minimum PHP Version Packagist GitHub repo size

The helpers allows you to Request processing. Get value for POST/GET/REQUEST method by key and set default value, check exist AJAX, POST and GET method - all this is available in this library.

Project repository: https://github.com/cs-eliseev/helpers-request

DEMO

switch(true) {
    case Request::isAjax():
    case Request::isPost():
        Request::post('example', 5);
        break;
    case Request::isGet():
        Request::getRequestUri();
        break;
}

Introduction

CSE HELPERS is a collection of several libraries with simple functions written in PHP for people.

Despite using PHP as the main programming language for the Internet, its functions are not enough. REQUEST CSE HELPERS solves the problem set default value to POST, GET and REQUEST method, and check exist AJAX, POST and GET method.

CSE HELPERS was created for the rapid development of web applications.

CSE Helpers project:

Below you will find some information on how to init library and perform common commands.

Install

You can find the most recent version of this project here.

Composer

Execute the following command to get the latest version of the package:

composer require cse/helpers-request

Or file composer.json should include the following contents:

{
    "require": {
        "cse/helpers-request": "*"
    }
}

Git

Clone this repository locally:

git clone https://github.com/cs-eliseev/helpers-request.git

Download

Download the latest release here.

Usage

The class consists of static methods that are conveniently used in any project. See example examples-request.php.

POST data by key name

Example:

$_POST['example'] = 12345;
Request::post('example');
// 12345

Set default value:

Request::post('example_2', 12345);
// 12345

GET data by key name

Example:

$_GET['example'] = 12345;
Request::get('example');
// 12345

Set default value:

Request::get('example_2', 12345);
// 12345

REQUEST data by key name

Example:

$_REQUEST['example'] = 12345;
Request::request('example');
// 12345

Set default value:

Request::request('example_2', 12345);
// 12345

Is AJAX

Example:

$_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest';
Request::isAjax();
// true

Is POST

Example:

$_SERVER['REQUEST_METHOD'] = Request::METHOD_POST;
Request::isPost();
// true

Is GET

Example:

$_SERVER['REQUEST_METHOD'] = Request::METHOD_GET;
Request::isGet();
// true

Get request Uri

Example:

$_SERVER['HTTP_REFERER'] = '/link/example';
Request::getRequestUri();
// /link/example

Set default value:

Request::getRequestUri('/link/home');
// /link/home

Ajax Uri:

$_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest';
$_SERVER['REQUEST_URI'] = '/link/example_ajax';
Request::getRequestUri();
// /link/example_ajax

Is redirect to HTTPS

Example:

Request::isRedirectedToHttps('http://google.com');
// true

Testing & Code Coverage

PHPUnit is used for unit testing. Unit tests ensure that class and methods does exactly what it is meant to do.

General PHPUnit documentation can be found at https://phpunit.de/documentation.html.

To run the PHPUnit unit tests, execute:

phpunit PATH/TO/PROJECT/tests/

If you want code coverage reports, use the following:

phpunit --coverage-html ./report PATH/TO/PROJECT/tests/

Used PHPUnit default config:

phpunit --configuration PATH/TO/PROJECT/phpunit.xml

Donating

You can support this project here. You can also help out by contributing to the project, or reporting bugs. Even voicing your suggestions for features is great. Anything to help is much appreciated.

License

The REQUEST CSE HELPERS is open-source PHP library licensed under the MIT license. Please see License File for more information.

GitHub @cs-eliseev