2.1 HTTP Response, Controller and Router Objects - marcos-c/sketch-php GitHub Wiki

SketchResponse class in library/Sketch/Response.php SketchController class in library/Sketch/Controller.php SketchRouter abstract class in library/Sketch/Router/Factory.php SketchRouterFactory class in library/Sketch/Router/Factory.php

The HTTP response object abstracts the body of the HTTP response that is going to be sent to the client as a DOMDocument.

The controller object takes care of instantiating this DOMDocument during bootstrap.

// Initialize controller
$controller = new SketchController();
$controller->setRouter(
    SketchRouterFactory::getRouter($application->getRequest())
);
$controller->setResponse(new SketchResponse());

The framework provides two routing systems.

SketchRouterDefault class in library/Sketch/Router/Default.php SketchRouterRewrite class in library/Sketch/Router/Rewrite.php

SketchRouterDefault provides linear routing. The called script calls itself and everything after the bootstrap is read as response.

SketchRouterRewrite provides mod_rewrite based routing with limited language and parameter matching support. The called script resolves the script to use as response from a conversion table defined in context.xml.

The controller delegates the instantiation of the response DOMDocument to the SketchResponsePart class.

SketchResponsePart class in library/Sketch/Response/Part.php

This class buffers the content of the script resolved by the router into a variable inside the constructor. Isolating it from the global variable space and providing an interface to commonly used services like logging and localization.

// $this resolves to the SketchResponsePart instance
// $this->_() is a shorter version of $this->getTranslator()->_()
<p class="count"><?=sprintf($this->_('%d offers found'), 10)?></p>