Oroboros Core
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Namespaces

  • None
  • oroboros
    • core
      • abstracts
        • adapters
        • bootstrap
        • controllers
        • libraries
          • auth
          • bootstrap
          • cache
          • codex
          • config
          • container
          • data
          • database
          • dns
          • entity
          • enum
          • error
          • event
          • extension
          • file
          • flags
          • hooks
          • job
          • logger
          • manager
          • message
          • prototype
          • request
          • response
          • routine
          • shell
          • startup
          • stream
          • template
          • uri
          • utility
          • validation
            • workers
          • worker
        • models
        • patterns
          • behavioral
          • creational
        • utilities
          • exception
            • cache
            • container
          • http
        • views
      • interfaces
        • adapters
          • interpreters
          • sdk
        • api
          • adapters
          • bootstrap
          • controllers
          • psr
        • contract
          • adapters
          • bootstrap
          • codex
          • components
          • controllers
          • data
          • entities
          • errors
          • events
          • extensions
          • jobs
          • libraries
            • auth
            • cache
            • config
            • container
            • enum
            • file
            • flags
            • hooks
            • module
            • promise
            • record
            • request
            • response
            • server
            • shutdown
            • site
            • stream
            • template
            • theme
            • uri
          • models
          • patterns
            • behavioral
            • concurrency
            • creational
            • structural
          • routes
          • routines
            • bootload
            • declarative
            • procedural
            • subsystem
          • services
            • consumer
              • cgi
              • rest
                • local
                • remote
                  • authenticated
                  • unauthenticated
            • provider
              • cgi
              • rest
                • local
                • remote
                  • authenticated
                  • unauthenticated
          • utilities
            • datetime
            • exception
              • cache
              • container
            • filebase
            • http
            • math
            • parser
            • regex
            • session
          • views
        • enumerated
          • environment
          • flags
          • http
          • views
        • libraries
          • manager
          • worker
      • libraries
        • api
        • codex
        • container
        • enum
          • http
        • file
        • hooks
        • logger
        • math
        • psr4
        • request
        • response
        • stream
        • uri
      • patterns
        • creational
      • traits
        • adapters
        • bootstrap
        • codex
        • components
        • controllers
        • data
        • entities
        • events
        • extensions
        • jobs
        • libraries
          • container
          • file
          • request
          • response
          • stream
          • uri
        • models
        • modules
        • patterns
          • behavioral
          • concurrency
          • creational
          • structural
        • routes
        • services
        • utilities
          • core
            • api
            • config
            • contract
              • contract
            • enum
            • environment
            • routines
          • datetime
          • error
          • exception
          • filebase
          • hooks
          • html
          • http
          • logic
          • math
          • parsers
          • regex
          • session
        • views
      • utilities
        • exception
          • cache
          • container
        • http
      • views
    • tests
      • patterns
        • creational
      • psr
        • psr7
      • utilities
        • exception
  • PasswordCompat
    • binary
  • PHP

Traits

  • MessageTrait
  • StreamTrait

Trait MessageTrait

Provides a set of methods to represent a Psr-7 message stream.

HTTP messages consist of requests from a client to a server and responses from a server to a client. This interface defines the methods common to each.

Messages are considered immutable; all methods that might change state MUST be implemented such that they retain the internal state of the current message and return an instance that contains the changed state.


Traits provide extended method support to classes without requiring a direct, linear chain of inheritance. This allows functions to inherit subsets of related methods without declaring a parent class.

In Oroboros core, ALL methods are granted to classes via traits, and the classes themselves are just containers that correlate their methods to an interface they are expected to honor. This approach maximizes interoperability, by entirely removing class inheritance as a requirement for extension of any class in this system.

3rd parties using this package are not expected to follow this approach,

but ALL of our internal class and logic structure does.

oroboros\core\traits\libraries\stream\MessageTrait uses oroboros\core\traits\libraries\stream\StreamTrait

Direct Known Users

oroboros\core\abstracts\libraries\stream\AbstractMessage, oroboros\core\traits\libraries\request\RequestTrait, oroboros\core\traits\libraries\response\ResponseTrait

Indirect Known Users

oroboros\core\libraries\stream\Message

Namespace: oroboros\core\traits\libraries\stream
Package: oroboros\core\psr7
Category: traits
License: The MIT License (MIT)
Author: Brian Dayhoff mopsyd@me.com
Version: 0.2.4
Since: 0.2.4-alpha
Used by: oroboros\core\interfaces\api\psr\Psr7Api::MESSAGE_ABSTRACT_CLASS
Link: bitbucket.org/oroborosframework/oroboros-core/wiki/development/api/traits.md
Link: http://www.ietf.org/rfc/rfc7230.txt
Link: http://www.ietf.org/rfc/rfc7231.txt
Satisfies: \oroboros\core\interfaces\contract\libraries\message\MessageContract
Satisfies: \Psr\Http\Message\MessageInterface
Located at core/traits/libraries/stream/MessageTrait.php

Methods summary

public
# __construct( scalar|resource|Psr\Http\Message\StreamInterface $body, array $headers = null, type $protocol = null )

Constructs a new instance of a Psr-7 message wrapper.

Constructs a new instance of a Psr-7 message wrapper.

Parameters

$body
This is the only required value for the constructor, and represents a message body as a scalar value, resource pointer, or instance of a stream interface.
$headers
(optional) If provided, represents an array of headers to construct with the message.
$protocol
(optional) If provided, the HTTP request protocol will be set to this value. Default value is "1.1"

Throws

oroboros\core\utilities\exception\InvalidArgumentException
if any passed parameters do not validate
public string
# getProtocolVersion( )

Retrieves the HTTP protocol version as a string.

Retrieves the HTTP protocol version as a string.

The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

Returns

string
HTTP protocol version.
public static
# withProtocolVersion( string $version )

Return an instance with the specified HTTP protocol version.

Return an instance with the specified HTTP protocol version.

The version string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new protocol version.

Parameters

$version
HTTP protocol version

Returns

static
public string[][]
# getHeaders( )

Retrieves all message header values.

Retrieves all message header values.

The keys represent the header name as it will be sent over the wire, and each value is an array of strings associated with the header. // Represent the headers as a string foreach ($message->getHeaders() as $name => $values) { echo $name . ': ' . implode(', ', $values); } // Emit headers iteratively: foreach ($message->getHeaders() as $name => $values) { foreach ($values as $value) { header(sprintf('%s: %s', $name, $value), false); } }

While header names are not case-sensitive, getHeaders() will preserve the exact case in which headers were originally specified.

Returns

string[][]

Returns an associative array of the message's headers. Each key MUST be a header name, and each value MUST be an array of strings for that header.

public boolean
# hasHeader( string $name )

Checks if a header exists by the given case-insensitive name.

Checks if a header exists by the given case-insensitive name.

Parameters

$name
Case-insensitive header field name.

Returns

boolean

Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.

public string[]
# getHeader( string $name )

Retrieves a message header value by the given case-insensitive name.

Retrieves a message header value by the given case-insensitive name.

This method returns an array of all the header values of the given case-insensitive header name.

If the header does not appear in the message, this method MUST return an empty array.

Parameters

$name
Case-insensitive header field name.

Returns

string[]

An array of string values as provided for the given header. If the header does not appear in the message, this method MUST return an empty array.

public string
# getHeaderLine( string $name )

Retrieves a comma-separated string of the values for a single header.

Retrieves a comma-separated string of the values for a single header.

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

If the header does not appear in the message, this method MUST return an empty string.

Parameters

$name
Case-insensitive header field name.

Returns

string

A string of values as provided for the given header concatenated together using a comma. If the header does not appear in the message, this method MUST return an empty string.

public static
# withHeader( string $name, string|string[] $value )

Return an instance with the provided value replacing the specified header.

Return an instance with the provided value replacing the specified header.

While header names are case-insensitive, the casing of the header will be preserved by this function, and returned from getHeaders().

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new and/or updated header and value.

Parameters

$name
Case-insensitive header field name.
$value
Header value(s).

Returns

static

Throws

InvalidArgumentException
for invalid header names or values.
public static
# withAddedHeader( string $name, string|string[] $value )

Return an instance with the specified header appended with the given value.

Return an instance with the specified header appended with the given value.

Existing values for the specified header will be maintained. The new value(s) will be appended to the existing list. If the header did not exist previously, it will be added.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new header and/or value.

Parameters

$name
Case-insensitive header field name to add.
$value
Header value(s).

Returns

static

Throws

InvalidArgumentException
for invalid header names.
InvalidArgumentException
for invalid header values.
public static
# withoutHeader( string $name )

Return an instance without the specified header.

Return an instance without the specified header.

Header resolution MUST be done without case-sensitivity.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that removes the named header.

Parameters

$name
Case-insensitive header field name to remove.

Returns

static
public StreamInterface
# getBody( )

Gets the body of the message.

Gets the body of the message.

Returns

StreamInterface
Returns the body as a stream.
public static
# withBody( Psr\Http\Message\StreamInterface $body )

Return an instance with the specified message body.

Return an instance with the specified message body.

The body MUST be a StreamInterface object.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return a new instance that has the new body stream.

Parameters

$body
Body.

Returns

static

Throws

InvalidArgumentException
When the body is not valid.
protected
# _initializeMessage( mixed $body, resource|string $headers = null, array $protocol = null , string $protocol,… )

Creates a ready instance of a Psr-7 message stream.

Creates a ready instance of a Psr-7 message stream.

Parameters

$body
$headers
$source
$protocol
$headers
$protocol,…
protected array
# _getMessageHeaders( )

Returns the correctly structured header array.

Returns the correctly structured header array.

Returns

array
private
# _validateMessageHeader( string $name, string|string[] $value )

Validates header parameters according to Psr-7 standards.

Validates header parameters according to Psr-7 standards.

Parameters

$name
$value

Throws

oroboros\core\utilities\exception\InvalidArgumentException
private boolean
# _checkMessageHeader( string $name )

Checks if the supplied header name exists in a case-insensitive way.

Checks if the supplied header name exists in a case-insensitive way.

Parameters

$name

Returns

boolean
private
# _getMessageValidRequestHeaders( )

Initialization method to obtain the valid request headers from the dedicated enumerator.

Initialization method to obtain the valid request headers from the dedicated enumerator.

private
# _getMessageValidResponseHeaders( )

Initialization method to obtain the valid response headers from the dedicated enumerator.

Initialization method to obtain the valid response headers from the dedicated enumerator.

private
# _setMessageHeaders( array $headers )

Sets the headers passed into initialization as header objects, and sets an array of the names locally for reference.

Sets the headers passed into initialization as header objects, and sets an array of the names locally for reference.

Parameters

$headers
private
# _setMessageBody( scalar|Psr\Http\Message\StreamInterface $body )

Sets the message body as a stream resource. Accepts an existing resource, and creates one if passed a scalar value.

Sets the message body as a stream resource. Accepts an existing resource, and creates one if passed a scalar value.

Parameters

$body

Throws

oroboros\core\utilities\exception\InvalidArgumentException
if an invalid parameter type is passed (non-scalar, non-resource, not an instance of \Psr\Http\Message\StreamInterface )
private
# _setMessageProtocol( string $protocol )

Creates an object representation of the http protocol

Creates an object representation of the http protocol

Parameters

$protocol
private array
# _getMessageValues( )

Returns an array of the existing message values for this object, for substitution when returning instances that must retain object immutability.

Returns an array of the existing message values for this object, for substitution when returning instances that must retain object immutability.

Returns

array
private oroboros\core\traits\libraries\stream\MessageTrait
# _instantiateMessageNewInstance( array $params = null )

Creates a new instance based off of the default parameters, substituting any values passed in.

Creates a new instance based off of the default parameters, substituting any values passed in.

Parameters

$params

Returns

oroboros\core\traits\libraries\stream\MessageTrait

Methods used from oroboros\core\traits\libraries\stream\StreamTrait

__destruct(), __toString(), _createCacheStreamFile(), _createStreamCacheFileName(), _initializeStream(), close(), detach(), eof(), getContents(), getMetadata(), getSize(), isReadable(), isSeekable(), isWritable(), read(), rewind(), seek(), tell(), write()

Properties summary

private array $_message_headers

Represents the header values of headers passed in for the message.

Represents the header values of headers passed in for the message.

# array()
private array $_message_valid_protocols

Represents valid HTTP request methods. If HTTP/2 becomes prominent and supported at a later date, it will be added here also.

Represents valid HTTP request methods. If HTTP/2 becomes prominent and supported at a later date, it will be added here also.

# array( '1.0', '1.1', )
private string $_message_protocol_default

Represents the default HTTP transfer protocol.

Represents the default HTTP transfer protocol.

# '1.1'
private oroboros\core\utilities\http\Protocol $_message_protocol

The current message protocol.

The current message protocol.

#
private boolean $_message_is_initialized

Represents whether the message is properly initialized.

Represents whether the message is properly initialized.

# false
private static array $_message_headers_valid
# array( 'request' => array(), 'response' => array() )

Properties used from oroboros\core\traits\libraries\stream\StreamTrait

$_cache_file, $_meta, $_offset, $_purge_file_on_destruct, $_readable, $_seekable, $_size, $_stream, $_uri, $_writeable

Oroboros Core API documentation generated by ApiGen