PHP Classes
elePHPant
Icontem

PHP HTTP Request Class: Check the HTTP request and extract its parameters

Recommend this page to a friend!
  Info   View files Documentation   View files View files (14)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-05-17 (4 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 93 This week: 93All time: 8,974 This week: 4Up
Version License PHP version Categories
php-request 1.1.4MIT/X Consortium ...5.6HTTP, PHP 5
Description Author

This class can check the HTTP request and extract its parameters.

It provides static functions to check the type of method, as well extract relevant parameters accessing the specific PHP variables and functions.

The class can handle requests of type GET, POST, FILES, PUT and DELELE.

  Performance   Level  
Name: Josantonius is available for providing paid consulting. Contact Josantonius .
Classes: 30 packages by
Country: Spain Spain
Age: ???
All time rank: 161137 in Spain Spain
Week rank: 1 Up
Innovation award
Innovation award
Nominee: 11x

Details

PHP Request library

Latest Stable Version Latest Unstable Version License Codacy Badge Total Downloads Travis PSR2 PSR4 CodeCov

Versión en español

PHP library for handling requests.

Requirements

This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.

Installation

The preferred way to install this extension is through Composer.

To install PHP Request library, simply:

$ composer require Josantonius/Request

The previous command will only install the necessary files, if you prefer to download the entire source code you can use:

$ composer require Josantonius/Request --prefer-source

You can also clone the complete repository with Git:

$ git clone https://github.com/Josantonius/PHP-Request.git

Or install it manually:

Download Request.php:

$ wget https://raw.githubusercontent.com/Josantonius/PHP-Request/master/src/Request.php

Available Methods

Available methods in this library:

- Secure access to GET parameters:

Request::get($key);

| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $key | Parameter key. | string | Yes | |

# Return (mixed|null) ? value or null

- Secure access to POST parameters:

Request::post($key);

| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $key | Parameter key. | string | Yes | |

# Return (mixed|null) ? value or null

- Secure access to FILES parameters:

Request::files($key);

| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $key | Parameter key. | string | Yes | |

# Return (mixed|null) ? value or null

- Secure access to PUT parameters:

Request::put($key);

| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $key | Parameter key. | string | Yes | |

# Return (mixed|null) ? value or null

- Secure access to DEL parameters:

Request::del($key);

| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $key | Parameter key. | string | Yes | |

# Return (mixed|null) ? value or null

- Check if it's a GET request:

Request::isGet();

# Return (boolean)

- Check if it's a POST request:

Request::isPost();

# Return (boolean)

- Check if it's a PUT request:

Request::isPut();

# Return (boolean)

- Check if it's a DELETE request:

Request::isDelete();

# Return (boolean)

- Check if it's a AJAX request:

Request::isAjax();

# Return (boolean)

Quick Start

To use this library with Composer:

require __DIR__ . '/vendor/autoload.php';

use Josantonius\Request\Request;

Or If you installed it manually, use it:

require_once __DIR__ . '/Request.php';

use Josantonius\Request\Request;

Usage

Example of use for this library:

- Access to all GET parameters:

$_GET = ['test' => 'value', 'test-2' => 1];

Request::get();

- Access to GET specific key parameter:

$_GET = ['test' => 'value', 'test-2' => 1];

Request::get('test');

- Access to all POST parameters:

$_POST = ['test' => 'value', 'test-2' => 1];

Request::post();

- Access to POST specific key parameter:

$_POST = ['test' => 'value', 'test-2' => 1];

Request::post('test');

- Access to all FILES parameters:

$_FILES = ['test' => 'value', 'test-2' => 1];

Request::files();

- Access to FILES specific key parameter:

$_FILES = ['test' => 'value', 'test-2' => 1];

Request::files('test');

- Access to all PUT parameters:

$_PUT = ['test' => 'value', 'test-2' => 1];

Request::put();

- Access to PUT specific key parameter:

$_PUT = ['test' => 'value', 'test-2' => 1];

Request::put('test');

- Check if it's a POST request:

$_SERVER['REQUEST_METHOD'] = 'POST';

Request::isPost()

- Check if it's a PUT request:

$_SERVER['REQUEST_METHOD'] = 'PUT';

Request::isPut()

- Check if it's a DELETE request:

$_SERVER['REQUEST_METHOD'] = 'DELETE';

Request::isDelete()

- Check if it's a AJAX request:

$_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest';

Request::isAjax()

Tests

To run tests you just need composer and to execute the following:

$ git clone https://github.com/Josantonius/PHP-Request.git

$ cd PHP-Request

$ composer install

Run unit tests with PHPUnit:

$ composer phpunit

Run PSR2 code standard tests with PHPCS:

$ composer phpcs

Run PHP Mess Detector tests to detect inconsistencies in code style:

$ composer phpmd

Run all previous tests:

$ composer tests

? TODO

  • [ ] Add new feature.
  • [ ] Improve tests.
  • [ ] Improve documentation.
  • [ ] Refactor code for disabled code style rules. See phpmd.xml and .php_cs.dist.

Contribute

If you would like to help, please take a look at the list of issues or the To Do checklist.

Pull requests

  • Fork and clone.
  • Run the command composer install to install the dependencies. This will also install the dev dependencies.
  • Run the command composer fix to excute code standard fixers.
  • Run the tests.
  • Create a branch, commit, push and send me a pull request.

Thank you to all the people who already contributed to this project!

<img alt="peter279k" src="https://avatars2.githubusercontent.com/u/9021747?v=4&s=117" height="117" width="117"> | :---:| peter279k|

Repository

The file structure from this repository was created with PHP-Skeleton.

License

This project is licensed under MIT license. See the LICENSE file for more info.

Copyright

2017 - 2018 Josantonius, josantonius.com

If you find it useful, let me know :wink:

You can contact me on Twitter or through my email.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetests (1 file)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .php_cs.dist Example Example script
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONDUCT.md Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.xml Data Auxiliary data
Accessible without login Plain text file phpmd.xml Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README-ES.md Doc. Documentation
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file Request.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file RequestTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:93
This week:93
All time:8,974
This week:4Up