Download the PHP package patricksavalle/slim-request-params without Composer

On this page you can find all versions of the php package patricksavalle/slim-request-params. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package slim-request-params

PHP SLIM Request validation

Needs PHP 7.x

Validates request query-parameters and body-parameters ($_GET and $_BODY) and HTTP-headers using regular expressions. Adds a layer of security and self-documentation to your API-code. Uses the same syntax as SLIM uses for route-segments.

Example:

use SlimRequestParams\QueryParameters;

$slimapp->get('', ...)
    ->add(new QueryParameters([
        '{text:\w+}',
        '{fromdate:\date}',
        '{distance:\float},0.0',
        '{orderby:(name|date)},name',
        '{reversed:\bool},false',
        '{offset:\int},1',
        '{count:\int},100',
    ]);

This would for example accept this request:

GET yourdomain.com?text=airplane&fromdate=2016-10-10

And it would for example reject these requests:

GET yourdomain.com?text=airplane&fromdate=2016-10-10&whatever=23
GET yourdomain.com?text=airplane&fromdate=date
GET yourdomain.com?fromdate=2016-10-10&whatever=23
GET yourdomain.com?text=airplane&
GET yourdomain.com

etc.

0. Install with Composer

1. Add the middleware to the SLIM routes

To validate request parameters:

use SlimRequestParams\QueryParameters;

$slimapp->get(...)
    ->add(new QueryParameters([
        '{author:[\w-. @]+}',
        '{orderby:\w+},id',
        '{reversed:1},1',
        '{offset:\int},1',
        '{count:\int},100',
        '{*}',
    ])

To validate body parameters (posted by client as x-www-form-urlencoded):

use SlimRequestParams\BodyParameters;

$slimapp->post(...)
    ->add(new BodyParameters([
        '{recipient:.*}',
        '{sender:.*}',
        '{subject:.*}',
        '{timestamp:.*}',
        '{token:.*}',
        '{signature:.*}',
        '{*}',
    ]));

To validate request headers (make sure they are present and their values follows a specific pattern):

use SlimRequestParams\RequestHeaders;

$slimapp->post(...)
    ->add(new RequestHeaders([
        '{HTTP_REFERER:\url}',
        '{HTTP_CB_SIGNATURE:.*}',
    ]));

To forbid arguments to a route:

$slimapp->get(...)
    ->add(new QueryParameters)

General format of a validation rule:

{<name>:<regex>},<optional_default_value>

Missing parameters are set to the given default.

Explicitely setting a value to null:

/someurl?key=  (leave value empty) 

Extra parameters generate an error unless the wildcard parameter is used: {*} in which case the extra parameters are passed without validation.

Accepts the RFC-standard query parameter array, not the PHP version:

/someurl?a=10&a=11&a=12

For typed parameters and special formats there are the following keywords that can be used instead of the regex:

\boolean
\int
\float
\date
\raw
\base64json
\url
\email
\country
\nationality
\timezone
\currency
\language
\bitcoinaddress
\moneroaddress
\xtext   (a XHTML fragment only using text formatting tags, tidies up the text)

These are only syntax checks! Also there is an accept 'anything else' argument:

{*}

Optional parameters should get the default:

\optional

(See code example above)

The RequestHeaders Middleware always accept 'anything else'.

2. Install the strategy in SLIM3.x for access to the validated arguments

Add the strategy that combines the url-, query- and post-parameters and request-headers into one object.

$slimapp->getContainer()['foundHandler'] = function () {
    return new RequestResponseArgsObject;
};        

3. Adapt your route handlers to the new strategy

A complete example.

<?php

declare(strict_types = 1);

namespace YourApi;

define("BASE_PATH", dirname(__FILE__));

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

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use \SlimRequestParams\BodyParameters;
use \SlimRequestParams\QueryParameters;
use \SlimRequestParams\RequestResponseArgsObject;

$app = new \Slim\App;

$app->getContainer()['foundHandler'] = function () {
    return new RequestResponseArgsObject;
};

$app->get('/hello/{name}', function (Request $request, Response $response, \stdClass $args) {
    $name = $args->name;
    $text = $args->text;
    $referer = $args->referer;
    $response->getBody()->write("$text, $name, $referer");
    return $response;
})
    ->add(new RequestHeaders(['{HTTP_REFERER:\url']))
    ->add(new QueryParameters(['{text:[\w-.~@]+},Hello']));

$app->run();

To retrieve or inspect the validated parameters from anywhere in your app just use:

\SlimRequestParams\QueryParameters::get();
\SlimRequestParams\BodyParameters::get();
\SlimRequestParams\RequestHeaders::get();

All versions of slim-request-params with dependencies

PHP Build Version
Package Version
Requires slim/slim Version ^3.0
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package patricksavalle/slim-request-params contains the following files

Loading the files please wait ....