-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer.php
51 lines (43 loc) · 1.61 KB
/
container.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
<?php
/******************************************************************************
* Represents a generic self-contained unit of web content. Usually HTML, but *
* might be JSON or whatever else. *
* *
* Containers are generally created using output buffering, so that you can *
* capture things like the contents of the main page being displayed, as well *
* as treat things like PHP file output as string values. *
* *
* $content is generally said string value. *
******************************************************************************/
requireOnceRoot('general.php');
abstract class Container
{
private $content;
// Create initial contents of the container upon creation.
public function __construct($string = '')
{
$this->content = $string;
}
// Return an indented copy of the container's contents.
private function indent($indent)
{
$line_start = str_repeat(General::INDENT(), $indent);
$output = str_replace("\n", "\n" . $line_start, $this->content);
return sprintf("%s\n", $output);
}
// Put the contents of the output buffer into the container.
protected function processBuffer()
{
$this->content .= ob_get_contents();
ob_end_clean();
}
// Get the contents of the container, optionally indenting.
public function getContent($indent = 0)
{
if ($indent === 0) {
return $this->content;
} else {
return $this->indent($indent);
}
}
}