PHP Class lithium\net\http\Service

Inheritance: extends lithium\core\Object
Mostra file Open project: unionofrad/lithium Class Usage Examples

Public Properties

Property Type Description
$connection lithium\net\Socket The Socket instance used to send Service calls.
$last object Holds the last request and response object

Protected Properties

Property Type Description
$_autoConfig array Auto config
$_classes array Fully-name-spaced class references to Service class dependencies.
$_isConnected boolean Defaults to true until a connection attempt fails.
$_responseTypes array Array of closures that return various pieces of information about an HTTP response.

Public Methods

Method Description
__call ( string $method, string $params = [] ) : mixed Magic method to handle other HTTP methods.
__construct ( array $config = [] ) : void Constructor. Initializes a new Service instance with the default HTTP request settings and transport- and format-handling classes.
delete ( string $path = null, array $data = [], array $options = [] ) : string Send DELETE request.
get ( string $path = null, array $data = [], array $options = [] ) : string Send GET request.
head ( string $path = null, array $data = [], array $options = [] ) : string Send HEAD request.
patch ( string $path = null, array $data = [], array $options = [] ) : string Send PATCH request.
post ( string $path = null, array $data = [], array $options = [] ) : string Send POST request.
put ( string $path = null, array $data = [], array $options = [] ) : string Send PUT request.
respondsTo ( string $method, boolean $internal = false ) : boolean Determines if a given method can be called.
send ( string $method, string $path = null, array $data = [], array $options = [] ) : string Send request and return response data. Will open the connection if needed and always close it after sending the request.

Protected Methods

Method Description
_init ( ) : void Initialize connection.
_request ( string $method, string $path, string $data, string $options ) : object Instantiates a request object (usually an instance of http\Request) and tests its properties based on the request type and data to be sent.

Method Details

__call() public method

Magic method to handle other HTTP methods.
public __call ( string $method, string $params = [] ) : mixed
$method string
$params string
return mixed

__construct() public method

Constructor. Initializes a new Service instance with the default HTTP request settings and transport- and format-handling classes.
public __construct ( array $config = [] ) : void
$config array Available configuration options are: - `'persistent'` _boolean_ - `'scheme'` _string_ - `'host'` _string_ - `'port'` _integer_ - `'timeout'` _integer_ - `'auth'` _boolean_ - `'username'` _string_ - `'password'` _string_ - `'encoding'` _string_ - `'socket'` _string_
return void

_init() protected method

Initialize connection.
protected _init ( ) : void
return void

_request() protected method

Instantiates a request object (usually an instance of http\Request) and tests its properties based on the request type and data to be sent.
protected _request ( string $method, string $path, string $data, string $options ) : object
$method string The HTTP method of the request, i.e. `'GET'`, `'HEAD'`, `'OPTIONS'`, etc. Can be passed in upper- or lower-case.
$path string The
$data string
$options string
return object Returns an instance of `http\Request`, configured with an HTTP method, query string or POST/PUT/PATCH data, and URL.

delete() public method

Send DELETE request.
public delete ( string $path = null, array $data = [], array $options = [] ) : string
$path string
$data array
$options array
return string

get() public method

Send GET request.
public get ( string $path = null, array $data = [], array $options = [] ) : string
$path string
$data array
$options array
return string

head() public method

Send HEAD request.
public head ( string $path = null, array $data = [], array $options = [] ) : string
$path string
$data array
$options array
return string

patch() public method

Send PATCH request.
public patch ( string $path = null, array $data = [], array $options = [] ) : string
$path string
$data array
$options array
return string

post() public method

Send POST request.
public post ( string $path = null, array $data = [], array $options = [] ) : string
$path string
$data array
$options array
return string

put() public method

Send PUT request.
public put ( string $path = null, array $data = [], array $options = [] ) : string
$path string
$data array
$options array
return string

respondsTo() public method

Determines if a given method can be called.
public respondsTo ( string $method, boolean $internal = false ) : boolean
$method string Name of the method.
$internal boolean Provide `true` to perform check from inside the class/object. When `false` checks also for public visibility; defaults to `false`.
return boolean Returns `true` if the method can be called, `false` otherwise.

send() public method

Will automatically authenticate when receiving a 401 HTTP status code then continue retrying sending initial request.
public send ( string $method, string $path = null, array $data = [], array $options = [] ) : string
$method string
$path string
$data array the parameters for the request. For GET/DELETE this is the query string for POST/PUT this is the body
$options array passed to request and socket
return string

Property Details

$_autoConfig protected_oe property

Auto config
protected array $_autoConfig
return array

$_classes protected_oe property

Fully-name-spaced class references to Service class dependencies.
protected array $_classes
return array

$_isConnected protected_oe property

Defaults to true until a connection attempt fails.
protected bool $_isConnected
return boolean

$_responseTypes protected_oe property

Array of closures that return various pieces of information about an HTTP response.
protected array $_responseTypes
return array

$connection public_oe property

The Socket instance used to send Service calls.
public lithium\net\Socket $connection
return lithium\net\Socket

$last public_oe property

Holds the last request and response object
public object $last
return object