Skip to content

Commit

Permalink
Fix syntax in dispatch cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Jul 24, 2014
1 parent 5b16fd5 commit 57bb6ff
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 69 deletions.
10 changes: 4 additions & 6 deletions src/Core/Start.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,27 @@
namespace Gt\Core;
use \Gt\Request\Standardiser;
use \Gt\Request\Request;
use \Gt\Response\Redirect;
use \Gt\Response\Response;
use \Gt\Api\ApiFactory;
use \Gt\Database\DatabaseFactory;
use \Gt\Dispatcher\DispatcherFactory;

final class Start {

private $config;

public function __construct($uri) {
if(empty($_SERVER)) {
throw new \Gt\Core\Exception\UndefinedVariableException(
"\$_SERVER is not defined. Are you running from cli?");
}

$this->config = new Config();
$config = new Config();

$standardiser = new Standardiser();
$uriFixed = $standardiser->fixUri($uri, $this->config["request"]);
$uriFixed = $standardiser->fixUri($uri, $config["request"]);
if($uri !== $uriFixed) {
// Only perform permanent redirects on production applications.
$code = 302;
if($this->config["app"]->production) {
if($config["app"]->production) {
$code = 301;
}

Expand Down
12 changes: 11 additions & 1 deletion src/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,20 @@ public function __construct(Request $request, Response $response,
$this->dbFactory = $dbFactory;
}

/**
* Creates a suitable ResponseContent object for the type of dispatcher.
* For a PageDispatcher, the ResponseContent will be a Gt\Response\Dom\Document
* @return ResponseContent The object to serialise as part of the HTTP response
*/
abstract function createResponseContent();

/**
* Performs the dispatch cycle.
*/
public function process() {
// Create and assign the Response content. This object may represent a
// DOMDocument or ApiObject, depending on request type.
$content = ResponseContentFactory::create($this->request->getType());
$content = $this->createResponseContent();

// Construct and assign ResponseCode object, which is a collection of
// Code class instantiations in order of execution.
Expand Down
2 changes: 1 addition & 1 deletion src/Dispatcher/DispatcherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
namespace Gt\Dispatcher;
use Gt\Request\Request;
use Gt\Request\Response;
use Gt\Response\Response;
use Gt\Api\ApiFactory;
use Gt\Database\DatabaseFactory;

Expand Down
11 changes: 11 additions & 0 deletions src/Dispatcher/PageDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@
namespace Gt\Dispatcher;
class PageDispatcher extends Dispatcher {

public function createResponseContent() {
$domDocument = new \Gt\Response\Dom\Document();

$htmlPath = $this->getPath(Dispatcher::PATH_HTML);
$htmlArray = [];

$domDocument->load($htmlArray);

return $domDocument;
}

}#
11 changes: 0 additions & 11 deletions src/Response/ApiResponse.php

This file was deleted.

16 changes: 14 additions & 2 deletions src/Response/Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ class Document extends ResponseContent {
private $domDocument;

public function __construct() {
$this->domDocument = new DOMDocument("1.0", "utf-8");
$this->domDocument = new \DOMDocument("1.0", "utf-8");
}

public function load($response) {

public function serialize() {
// TODO: Serialize
}

/**
* Synonym for unserialize.
*/
public function load($content) {
return $this->unserialize($content);
}

public function unserialize($serialized) {
libxml_use_internal_errors(true);

$html = "<!doctype html>";
Expand Down
23 changes: 0 additions & 23 deletions src/Response/ResponseCodeFactory.php

This file was deleted.

13 changes: 11 additions & 2 deletions src/Response/ResponseContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
* @copyright Copyright Ⓒ 2014 Bright Flair Ltd. (http://brightflair.com)
* @license Apache Version 2.0, January 2004. http://www.apache.org/licenses
*/
abstract class ResponseContent {
namespace Gt\Response;

abstract class ResponseContent implements \Serializable {

/**
* Serialises the response in its current state and adds it to the output
* buffer, ready for flushing at the end of the response cycle.
*/
public function send();
abstract function serialize();

/**
* Loads a string representation of the current ResponseContent. Page requests
* will load raw HTML for the Dom Document, API requests will load a PHP
* object serialized string.
*/
abstract function unserialize($serialized);

}#
23 changes: 0 additions & 23 deletions src/Response/ResponseContentFactory.php

This file was deleted.

0 comments on commit 57bb6ff

Please sign in to comment.