-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebsite.php
76 lines (69 loc) · 2.09 KB
/
Website.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Sledgehammer\Mvc;
use Exception;
use Sledgehammer\Core\Debug\DebugR;
use Sledgehammer\Mvc\Component\HttpError;
use Sledgehammer\Mvc\Document\Page as HtmlDocument;
/**
* Superclass for the Website classes.
* DesignPatterns: FrontController, Command, Chain of Responsibility.
*/
abstract class Website extends Folder
{
public function __construct()
{
parent::__construct();
$this->publicMethods = array_diff($this->publicMethods, ['handleRequest', 'generateDocument', 'statusbar', 'initLanguage', 'isWrapable']); // Een aantal functies *niet* public maken
}
/**
* Send a response based on the request.
*/
public function handleRequest()
{
// Build document
$document = $this->generateDocument();
if (!defined('Sledgehammer\GENERATED')) {
define('Sledgehammer\GENERATED', microtime(true));
}
// Send headers
$headers = $document->getHeaders();
\Sledgehammer\send_headers($headers['http']);
// Send the sledgehammer-statusbar as DebugR header.
if (DebugR::isEnabled()) {
ob_start();
statusbar();
DebugR::send('sledgehammer-statusbar', ob_get_clean(), true);
}
// Send the contents
$document->render();
}
/**
* Generate a Document for this request.
*
* @return Document
*/
public function generateDocument()
{
try {
$content = $this->generateContent();
} catch (Exception $exception) {
$content = new HttpError(500, ['exception' => $exception]);
}
$isDocument = false;
if (method_exists($content, 'isDocument')) {
$isDocument = $content->isDocument();
}
if ($isDocument) {
return $content;
}
$document = new HtmlDocument();
$document->content = $this->wrapContent($content);
return $document;
}
/**
* Embed the component inside your Layout View.
*
* @return Component
*/
abstract protected function wrapContent($content);
}