josantonius/request

1.1.6 2017-11-13 19:59 UTC

README

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

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.

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 Josantonius, josantonius.com

If you find it useful, let me know 😉

You can contact me on Twitter or through my email.