Class Stream

Implements sending Cake\Network\Http\Request via php's stream API.

This approach and implementation is partly inspired by Aura.Http

Properties summary

  • $_connectionErrors protected
    array
    Connection error list.
  • $_context protected
    resource
    Context resource used by the stream API.
  • $_contextOptions protected
    array
    Array of options/content for the HTTP stream context.
  • array
    Array of options/content for the SSL stream context.
  • $_stream protected
    resource
    The stream resource.

Method Summary

  • _buildContent() protected
    Builds the request content based on the request object.
  • _buildContext() protected
    Build the stream context out of the request object.
  • _buildHeaders() protected
    Build the header context for the request.
  • _buildOptions() protected
    Build miscellaneous options for the request.
  • _buildSslContext() protected
    Build SSL options for the request.
  • Local error handler to capture errors triggered during stream connection.

  • _open() protected
    Open the socket and handle any connection errors.
  • _send() protected
    Open the stream and send the request.
  • Get the context options
  • Create the response list based on the headers & content
  • send() public
    Send a request and get a response back.

Method Detail

_buildContent()source protected

_buildContent( Cake\Network\Http\Request $request , array $options )

Builds the request content based on the request object.

If the $request->body() is a string, it will be used as is. Array data will be processed with Cake\Network\Http\FormData

Parameters

Cake\Network\Http\Request $request
The request being sent.
array $options
Array of options to use.

_buildContext()source protected

_buildContext( Cake\Network\Http\Request $request , array $options )

Build the stream context out of the request object.

Parameters

Cake\Network\Http\Request $request
The request to build context from.
array $options
Additional request options.

_buildHeaders()source protected

_buildHeaders( Cake\Network\Http\Request $request , array $options )

Build the header context for the request.

Creates cookies & headers.

Parameters

Cake\Network\Http\Request $request
The request being sent.
array $options
Array of options to use.

_buildOptions()source protected

_buildOptions( Cake\Network\Http\Request $request , array $options )

Build miscellaneous options for the request.

Parameters

Cake\Network\Http\Request $request
The request being sent.
array $options
Array of options to use.

_buildSslContext()source protected

_buildSslContext( Cake\Network\Http\Request $request , array $options )

Build SSL options for the request.

Parameters

Cake\Network\Http\Request $request
The request being sent.
array $options
Array of options to use.

_connectionErrorHandler()source protected

_connectionErrorHandler( integer $code , string $message )

Local error handler to capture errors triggered during stream connection.

Parameters

integer $code
Error code.
string $message
Error message.

_open()source protected

_open( string $url )

Open the socket and handle any connection errors.

Parameters

string $url
The url to connect to.

Throws

Cake\Core\Exception\Exception

_send()source protected

_send( Cake\Network\Http\Request $request )

Open the stream and send the request.

Parameters

Cake\Network\Http\Request $request
The request object.

Returns

array
Array of populated Response objects

Throws

Cake\Core\Exception\Exception

contextOptions()source public

contextOptions( )

Get the context options

Useful for debugging and testing context creation.

Returns

array

createResponses()source public

createResponses( array $headers , string $content )

Create the response list based on the headers & content

Creates one or many response objects based on the number of redirects that occurred.

Parameters

array $headers
The list of headers from the request(s)
string $content
The response content.

Returns

array
The list of responses from the request(s)

send()source public

send( Cake\Network\Http\Request $request , array $options )

Send a request and get a response back.

Parameters

Cake\Network\Http\Request $request
The request object to send.
array $options
Array of options for the stream.

Returns

array
Array of populated Response objects

Properties detail

$_connectionErrorssource

protected array

Connection error list.

[]

$_contextsource

protected resource

Context resource used by the stream API.

$_contextOptionssource

protected array

Array of options/content for the HTTP stream context.

$_sslContextOptionssource

protected array

Array of options/content for the SSL stream context.

$_streamsource

protected resource

The stream resource.

© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/3.2/class-Cake.Network.Http.Adapter.Stream.html