/
Widget.php
executable file
·74 lines (60 loc) · 1.03 KB
/
Widget.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
<?php
/**
* a widget is an entity that:
*
* has a view that can be modified by the user (from db)
* has optinal stand-alone business logic
*
* on init it runs the business logic and fills _data with output results
*
*/
class Widget
{
protected $_data = array();
/**
* factory for text objects
*
* @param string $text
* @return Text
*/
public static function factory($widget)
{
// Set class name
$class = 'Widget_'.ucfirst($widget);
// create widget
$widget = new $class();
// call init
$widget->init();
// return an instance
return $widget;
}
protected function init()
{
// business logic
// output to _data
}
public function execute()
{
// business logic
// output to _data
return $this;
}
/**
* Widget::data()
* get ot set data
*
* @param bool $var
* @param bool $val
* @return
*/
public function data($var=FALSE,$val=FALSE)
{
if($var===FALSE){
//get data
return $this->_data;
} else {
// set data
$this->_data[$var] = $val;
}
}
}