romeoz/rock-request

HTTP request library for PHP

0.14.3 2015-11-22 12:41 UTC

README

Latest Stable Version Total Downloads Build Status HHVM Status Coverage Status License

Features

  • Sanitizing http-variables
  • Standalone module/component for Rock Framework

Installation

From the Command Line:

composer require romeoz/rock-request

In your composer.json:

{
    "require": {
        "romeoz/rock-request": "*"
    }
}

Quick Start

use rock\request\Request;

// example url: http://site.com/foo/?page=1&foo[bar]=test

// returns relative URL
(new Request)->getUrl(); // output: /foo/?page=1&foo[bar]=test

// returns host
(new Request)->getHost(); // output: site.com

// returns query params
(new Request)->rawGet(); // output: ['page' => 1, 'foo' => ['bar' => 'test']]

// returns query params as multiple
(new Request)->rawGet(['foo', 'bar']); // output: test

// alternative approach
(new Request)->rawGet('foo.bar'); // output: test

####Sanitize

For sanitizing http-variables required install Rock Sanitize: composer require romeoz/rock-sanitize.

use rock\sanitize\Sanitize;

// example url: http://site.com/foo/?page=<b>-1</b>

// default sanitize: Sanitize::removeTags()->trim()->toType(); 
Request::get('page'); // output: -1

// Add custom sanitize
Request::get('page', null, Sanitize::removeTags()->trim()->positive()); // output: 1

Requirements

  • PHP 5.4+
  • For sanitizing http-variables required Rock Sanitize: composer require romeoz/rock-sanitize

All unbolded dependencies is optional

License

HTTP request library is open-sourced software licensed under the MIT license.