1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Brickrouge;
13
14 use Brickrouge\Element;
15
16 abstract class Widget extends Element
17 {
18 const CONSTRUCTOR = '#widget-constructor';
19
20 21 22 23 24 25
26 public function __construct($type, array $attributes=array())
27 {
28 $class = get_class($this);
29 $constructor = basename(strtr($class, '\\', '/'));
30
31 parent::__construct
32 (
33 $type, $attributes + array
34 (
35 self::CONSTRUCTOR => $constructor
36 )
37 );
38 }
39
40 protected function render_class(array $class_names)
41 {
42 $class = 'widget-' . \ICanBoogie\hyphenate($this[self::CONSTRUCTOR]);
43 $class_names[$class] = $class;
44
45 return parent::render_class($class_names);
46 }
47
48 protected function alter_dataset(array $dataset)
49 {
50 return parent::alter_dataset
51 (
52 $dataset + array
53 (
54 'widget-constructor' => $this[self::CONSTRUCTOR]
55 )
56 );
57 }
58
59 public function get_results(array $options=array())
60 {
61 throw new \Exception('The widget class %class does not implement results', array('%class' => get_class($this)));
62 }
63 }