1.2.10. Extending the Response

The Sapien Response class can be extended to provide other userland functionality. Properties

The properties on Response are private, which means you may not access them, except through the existing Response methods. You may add child properties as desired, though they would best be protected or private. Constructor

Response is constructorless. You may add any constructor you like, and do not have to call a parent constructor. Methods

Most of the methods on Response are public and final, which means you cannot extend or override them in child classes. This keeps their behavior consistent.

However, these Response methods are not final, and thus are open to extension:

  • public function setContent(mixed $content) : void
  • public function send() : void
  • public function sendContent() : void

You may override them at will (though of course you cannot change the signatures). In general:

  • Override setContent() to set up the Response properties in relation to the content. Be sure to call parent::setContent() to actually retain the content value.

  • Override send() to perform pre- and post-sending behaviors. Be sure to call parent::send() to actually send the Response.

  • Override sendContent() for custom or specialized emitting of the content value.