Request

package Klein

 Methods

Constructor

__construct(array $params_get, array $params_post, array $cookies, array $server, array $files, string $body) 

Create a new Request object and define all of its request data

access public

Parameters

$params_get

array

$params_post

array

$cookies

array

$server

array

$files

array

$body

string

Magic "__get" method

__get(string $param) : string

Allows the ability to arbitrarily request a parameter from this instance while treating it as an instance property

access public

Parameters

$param

string

The name of the parameter

Returns

string

Magic "__isset" method

__isset(string $param) : boolean

Allows the ability to arbitrarily check the existence of a parameter from this instance while treating it as an instance property

access public

Parameters

$param

string

The name of the parameter

Returns

boolean

Magic "__set" method

__set(string $param, mixed $value) : void

Allows the ability to arbitrarily set a parameter from this instance while treating it as an instance property

NOTE: This currently sets the "named" parameters, since that's the one collection that we have the most sane control over

access public

Parameters

$param

string

The name of the parameter

$value

mixed

The value of the parameter

Magic "__unset" method

__unset(string $param) : void

Allows the ability to arbitrarily remove a parameter from this instance while treating it as an instance property

access public

Parameters

$param

string

The name of the parameter

Gets the request body

body() : string
access public

Returns

string

Returns the cookies collection

cookies() : \Klein\DataCollection\DataCollection
access public

Returns

Create a new request object using the built-in "superglobals"

createFromGlobals() : \Klein\Request
Static

Returns the files collection

files() : \Klein\DataCollection\DataCollection
access public

Returns

Returns the headers collection

headers() : \Klein\DataCollection\HeaderDataCollection

Gets a unique ID for the request

id(boolean $hash) : string

Generates one on the first call

access public

Parameters

$hash

boolean

Whether or not to hash the ID on creation

Returns

string

Gets the request IP address

ip() : string
access public

Returns

string

Is the request secure?

isSecure() : boolean
access public

Returns

boolean

Gets the request method, or checks it against $is

method(string $is, boolean $allow_override) : string
// POST request example
$request->method() // returns 'POST'
$request->method('post') // returns true
$request->method('get') // returns false
access public

Parameters

$is

string

The method to check the current request method against

$allow_override

boolean

Whether or not to allow HTTP method overriding via header or params

Returns

string| boolean

Return a request parameter, or $default if it doesn't exist

param(string $key, mixed $default) : string
access public

Parameters

$key

string

The name of the parameter to return

$default

mixed

The default value of the parameter if it contains no value

Returns

string

Returns all parameters (GET, POST, named, and cookies) that match the mask

params(array $mask, boolean $fill_with_nulls) : array

Takes an optional mask param that contains the names of any params you'd like this method to exclude in the returned array

see \Klein\DataCollection\DataCollection::all()
access public

Parameters

$mask

array

The parameter mask array

$fill_with_nulls

boolean

Whether or not to fill the returned array with null values to match the given mask

Returns

array

Returns the GET parameters collection

paramsGet() : \Klein\DataCollection\DataCollection
access public

Returns

Returns the named parameters collection

paramsNamed() : \Klein\DataCollection\DataCollection
access public

Returns

Returns the POST parameters collection

paramsPost() : \Klein\DataCollection\DataCollection
access public

Returns

Get the request's pathname

pathname() : string
access public

Returns

string

Adds to or modifies the current query string

query(string $key, mixed $value) : string
access public

Parameters

$key

string

The name of the query param

$value

mixed

The value of the query param

Returns

string

Returns the server collection

server() : \Klein\DataCollection\DataCollection
access public

Returns

Gets the request URI

uri() : string
access public

Returns

string

Gets the request user agent

userAgent() : string
access public

Returns

string

 Properties

 

$body : string
access protected
 

$cookies : \Klein\DataCollection\DataCollection
access protected
 

$files : \Klein\DataCollection\DataCollection
access protected
 

$headers : \Klein\DataCollection\HeaderDataCollection
access protected
 

$id : string
access protected
 

$params_get : \Klein\DataCollection\DataCollection
access protected
 

$params_named : \Klein\DataCollection\DataCollection
access protected
 

$params_post : \Klein\DataCollection\DataCollection
access protected
 

$server : \Klein\DataCollection\ServerDataCollection
access protected