/
HtmlBlock.class.php
59 lines (52 loc) · 1.38 KB
/
HtmlBlock.class.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
<?php
Library::import('recess.framework.helpers.blocks.Block');
/**
* HtmlBlock is a Block that wraps around static HTML strings.
* It is often used in conjunction with Buffer which is a helper
* for automatically buffering output to blocks.
*
* @author Kris Jordan
*/
class HtmlBlock extends Block {
protected $contents = '';
/**
* HtmlBlock can be constructed with an optional string that denotes
* its initial contents. i.e. $block = new HtmlBlock('<p>hello world</p>');
* @param string Contents optional.
*/
public function __construct($contents = '') {
$this->contents = $contents;
}
/**
* If the block has contents, draw will output the contents and return true.
* If not, it will return false. HtmlBlock's draw takes no arguments and
* will never throw MissingArgumentsException.
*
* @see recess/framework/helpers/blocks/Block#draw()
*/
public function draw() {
if($this->contents !== '') {
echo $this->contents;
return true;
} else {
return false;
}
}
/**
* Return
* @see recess/recess/recess/framework/helpers/blocks/Block#__toString()
*/
public function __toString(){
return $this->contents;
}
public function set($contents) {
$this->contents = $contents;
}
public function append($contents) {
$this->contents .= $contents;
}
public function prepend($contents) {
$this->contents = $contents . $this->contents;
}
}
?>