forked from gleez/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.php
73 lines (61 loc) · 1.38 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
<?php
/**
* Widget base class
*
* All widgets should extend this class.
*
* @package Gleez\Widget
* @author Gleez Team
* @copyright (c) 2011-2014 Gleez Technologies
* @license http://gleezcms.org/license Gleez CMS License
*
* @todo Add docs
*/
abstract class Widget {
/**
* Widget Name
* @var string
*/
protected $name;
/**
* Widget Object
* @var Widget
*/
protected $widget;
/**
* Create a new widget instance
*
* Example:
* ~~~
* $widget = Widget::factory($name, $widget);
* ~~~
*
* @param string $name Widget name
* @param Widget $widget Widget object
* @return Widget
*/
public static function factory($name, $widget)
{
// get class name if it has slash for multiple widgets, ex menu/management or static/donate
$split_name = explode('/', $name);
$name = array_shift($split_name);
// Set class name
$widget_class = 'Widget_'.ucfirst($name);
$name = isset($split_name[0]) ? $split_name[0] : $name;
return new $widget_class($name, $widget);
}
public function __construct($name, $widget)
{
$this->name = $name;
$this->widget = $widget;
}
public function __toString()
{
return $this->render();
}
abstract public function info();
abstract public function form();
abstract public function save(array $post);
abstract public function delete(array $post);
abstract public function render();
}