PHP Classes

Mezon PHP HTTP Request Values: Get HTTP request parameters by a specific order

Recommend this page to a friend!
  Info   View files Documentation   View files View files (12)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 62 This week: 1All time: 10,413 This week: 560Up
Version License PHP version Categories
mezon-request 1.0MIT/X Consortium ...5HTTP, PHP 5, Security
Description 

Author

This package can get HTTP request parameters in a specific order.

It can retrieve the values of a parameter value passed to PHP from the HTTP request currently handling.

The package can also check if the user clicked a form submit button

It can also check if the user clicked a form checkbox or radio button.

The package can evaluate the parameter values in a certain order according to the following priority:

- HTTP authentication and authorization values

- Parameters extracted from the request by Mezon Router class

- HTTP request headers

- HTTP POST request parameters

- HTTP GET request parameters

Innovation Award
PHP Programming Innovation award nominee
April 2022
Number 6
PHP provides super-global variables to facilitate access to the values extracted from the current HTTP request.

Nowadays, many applications use router components that can parse the HTTP request to configure which controller class handles the HTTP request.

This package combines the features of PHP to extract HTTP request values with the quality of the Mezon router class to retrieve HTTP request values and route parameter values using the same code.

Manuel Lemos
Picture of Alexey Dodonov
  Performance   Level  
Name: Alexey Dodonov <contact>
Classes: 58 packages by
Country: Russian Federation Russian Federation
Age: ???
All time rank: 185254 in Russian Federation Russian Federation
Week rank: 52 Up2 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 13x

Documentation

Global access for request parameters

Intro

This class will help you to fetch data from $_POST and $_GET arrays.

Installation

Just print in console

composer require mezon/request

And that's all )

Learn more

More information can be found here:

Twitter

dev.to

Slack

How to start

The firs steps are quite simple

var_dump(Request::getParam('some-param', 'default'));// will be outputted 'default'

$_GET['some-param'] = 'some-value';
var_dump(Request::getParam('some-param'));// will be outputted 'some-value'

Fields priorities

In case you have the same parameters in $_GET, $_POST and other global arrays, then they will be prioritized in this way:

  • security tokens in HTTP headers
  • Router parameters
  • HTTP request headers
  • $_POST
  • $_GET

For example:

$_GET['some-param'] = 'get-value';
$_POST['some-param'] = 'post-value';

var_dump(Request::getParam('some-param'));// will be outputted 'post value'

Router parameters

You can pass your Router object to this class and fetch parameters for non-static routes:

Request::registerRouter(<your Mezon\Router object>);

Security tokens in HTTP headers

There are a way to fetch security token from headers:

  • Authentication
  • Authorization
  • Cgi-Authorization

For example if you will pass in headers something like that:

Authorization: Basic <some token>

And then call:

Request::getParam('session_id')

Then this call will return <some token>.

Wrappers

There are some convenient wrappers were implemented:

// will return true if the parameter exists
// will return false otherwise
Request::wasSubmitted('param-name')

Or wrapper for check-boxes:

Request::getChecked('param-name', ['switched on', 'switched off'])
Request::getChecked('param-name', [1, 0])
Request::getChecked('param-name', [true, false])

In this call the method getChecked will return the first element of the array which is passed as the second parameter. And the second element otherwise.


  Files folder image Files  
File Role Description
Files folder imageMezon (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file infection.json Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file psalm.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  Mezon  
File Role Description
Files folder imageTransport (1 file, 1 directory)

  Files folder image Files  /  Mezon  /  Transport  
File Role Description
Files folder imageTests (6 files)
  Plain text file Request.php Class Class source

  Files folder image Files  /  Mezon  /  Transport  /  Tests  
File Role Description
  Plain text file GetCheckedUnitTest.php Class Class source
  Plain text file GetParameterAsStringUnitTest.php Class Class source
  Plain text file GetParameterUnitTest.php Class Class source
  Plain text file GetRouterUnitTest.php Class Class source
  Plain text file RequestBaseTest.php Class Class source
  Plain text file WasSubmittedUnitTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:62
This week:1
All time:10,413
This week:560Up