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

  • ResponseTrait

Trait ResponseTrait

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

Representation of an outgoing, server-side response.

Per the HTTP specification, this interface includes properties for each of the following:

  • Protocol version
  • Status code and reason phrase
  • Headers
  • Message body

Responses 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\response\ResponseTrait uses oroboros\core\traits\libraries\stream\MessageTrait

Direct Known Users

oroboros\core\abstracts\libraries\response\AbstractResponse

Indirect Known Users

oroboros\core\libraries\response\Response

Namespace: oroboros\core\traits\libraries\response
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::RESPONSE_ABSTRACT_CLASS
Link: bitbucket.org/oroborosframework/oroboros-core/wiki/development/api/traits.md
Satisfies: \oroboros\core\interfaces\contract\libraries\request\ResponseContract
Satisfies: \Psr\Http\Message\ResponseInterface
Located at core/traits/libraries/response/ResponseTrait.php

Methods summary

public
# __construct( scalar|resource|Psr\Http\Message\StreamInterface $body, array $headers = null, string $protocol = null, integer $code = null, string $reason = 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"
$code
(optional) If provided, the HTTP status code. If not provided, defaults to 200.
$reason
(optional) If provided, the HTTP status code reason. If not provided, uses the default for the code

Throws

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

Gets the response status code.

Gets the response status code.

The status code is a 3-digit integer result code of the server's attempt to understand and satisfy the request.

Returns

integer
Status code.
public static
# withStatus( integer $code, string $reasonPhrase = '' )

Return an instance with the specified status code and, optionally, reason phrase.

Return an instance with the specified status code and, optionally, reason phrase.

If no reason phrase is specified, implementations MAY choose to default to the RFC 7231 or IANA recommended reason phrase for the response's status code.

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 updated status and reason phrase.

Parameters

$code
The 3-digit integer result code to set.
$reasonPhrase

The reason phrase to use with the provided status code; if none is provided, implementations MAY use the defaults as suggested in the HTTP specification.

Returns

static

Throws

InvalidArgumentException
For invalid status code arguments.

See

http://tools.ietf.org/html/rfc7231#section-6
http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
public string
# getReasonPhrase( )

Gets the response reason phrase associated with the status code.

Gets the response reason phrase associated with the status code.

Because a reason phrase is not a required element in a response status line, the reason phrase value MAY be empty. Implementations MAY choose to return the default RFC 7231 recommended reason phrase (or those listed in the IANA HTTP Status Code Registry) for the response's status code.

Returns

string
Reason phrase; must return an empty string if none present.

See

http://tools.ietf.org/html/rfc7231#section-6
http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
protected
# _initializeResponse( mixed $body, array $headers = null, array $protocol = null, string $code = null, $reason = null )

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

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

Parameters

$body
$headers
$source
$protocol
$headers
$code
$protocol
$reason
private
# _setResponseCode( integer $code )

Sets the response code if it is valid.

Sets the response code if it is valid.

Parameters

$code

Throws

oroboros\core\utilities\exception\InvalidArgumentException
if an invalid code is passed
private
# _setResponseReason( string $reason )

Sets the response reason.

Sets the response reason.

Parameters

$reason

Throws

oroboros\core\utilities\exception\InvalidArgumentException
if an invalid reason is passed
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\utilities\http\StatusCode
# _getResponseStatusCodeObject( type $code, type $message = '' )

Returns a status code object.

Returns a status code object.

Parameters

$code
$message

Returns

oroboros\core\utilities\http\StatusCode

Throws

oroboros\core\utilities\exception\InvalidArgumentException
if an invalid code is passed
private oroboros\core\traits\libraries\request\ResponseTrait
# _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\request\ResponseTrait

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

_checkMessageHeader(), _getMessageHeaders(), _getMessageValidRequestHeaders(), _getMessageValidResponseHeaders(), _initializeMessage(), _setMessageBody(), _setMessageHeaders(), _setMessageProtocol(), _validateMessageHeader(), getBody(), getHeader(), getHeaderLine(), getHeaders(), getProtocolVersion(), hasHeader(), withAddedHeader(), withBody(), withHeader(), withProtocolVersion(), withoutHeader()

Properties summary

private oroboros\core\utilities\http\StatusCode $_response_code

Represents the internal status code object

Represents the internal status code object

#
private boolean $_response_is_initialized

Represents whether the request has been correctly initialized.

Represents whether the request has been correctly initialized.

# false

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

$_message_headers, $_message_headers_valid, $_message_is_initialized, $_message_protocol, $_message_protocol_default, $_message_valid_protocols

Oroboros Core API documentation generated by ApiGen