-
Notifications
You must be signed in to change notification settings - Fork 5
/
block.php
97 lines (86 loc) · 2.02 KB
/
block.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php //-->
/*
* This file is part of the Eden package.
* (c) 2011-2012 Openovate Labs
*
* Copyright and license information can be found at LICENSE.txt
* distributed with this package.
*/
/**
* Base class for any class that defines an output block.
* A block is a default and customizable piece of output.
*
* @package Eden
* @category core
* @author Christian Blanquera cblanquera@openovate.com
*/
abstract class Eden_Block extends Eden_Class {
/* Constants
-------------------------------*/
/* Public Properties
-------------------------------*/
/* Protected Properties
-------------------------------*/
protected static $_blockRoot = NULL;
/* Private Properties
-------------------------------*/
private static $_global = array();
/* Get
-------------------------------*/
/* Magic
-------------------------------*/
public function __toString() {
try {
return (string) $this->render();
} catch(Exception $e) {
Eden_Error_Event::i()->exceptionHandler($e);
}
return '';
}
/* Public Methods
-------------------------------*/
/**
* returns location of template file
*
* @return string
*/
abstract public function getTemplate();
/**
* returns variables used for templating
*
* @return array
*/
abstract public function getVariables();
/**
* Transform block to string
*
* @param array
* @return string
*/
public function render() {
return Eden_Template::i()->set($this->getVariables())->parsePhp($this->getTemplate());
}
/**
* For one file Eden, you can set the default
* location of Eden's template to another location.
*
* @param string
* @return this
*/
public function setBlockRoot($root) {
Eden_Error::i()->argument(1, 'folder');
self::$_blockRoot = $root;
return $this;
}
/* Protected Methods
-------------------------------*/
protected function _getGlobal($value) {
if(in_array($value, self::$_global)) {
return false;
}
self::$_global[] = $value;
return $value;
}
/* Private Methods
-------------------------------*/
}