1: <?php
2:
3: namespace Charcoal\App\Template;
4:
5: // PSR-3 (logger) dependencies
6: use \Psr\Log\LoggerAwareInterface;
7: use \Psr\Log\LoggerAwareTrait;
8:
9: // Dependencies from `Pimple`
10: use \Pimple\Container;
11:
12: // Module `charcoal-config` dependencies
13: use \Charcoal\Config\AbstractEntity;
14:
15: // Module `charcoal-view` dependencies
16: use \Charcoal\View\ViewableInterface;
17: use \Charcoal\View\ViewableTrait;
18:
19: // Local namespace dependencies
20: use \Charcoal\App\Template\WidgetInterface;
21:
22: /**
23: *
24: */
25: abstract class AbstractWidget extends AbstractEntity implements
26: WidgetInterface,
27: LoggerAwareInterface,
28: ViewableInterface
29: {
30: use LoggerAwareTrait;
31: use ViewableTrait;
32:
33: /**
34: * @var boolean $active
35: */
36: private $active = true;
37:
38: /**
39: * @param array|\ArrayAccess $data Optional dependencies.
40: */
41: public function __construct($data = null)
42: {
43: $this->setLogger($data['logger']);
44:
45: if (isset($data['container'])) {
46: $this->setDependencies($data['container']);
47: }
48: }
49:
50: /**
51: * Give an opportunity to children classes to inject dependencies from a Pimple Container.
52: *
53: * Does nothing by default, reimplement in children classes.
54: *
55: * The `$container` DI-container (from `Pimple`) should not be saved or passed around, only to be used to
56: * inject dependencies (typically via setters).
57: *
58: * @param Container $container A dependencies container instance.
59: * @return void
60: */
61: public function setDependencies(Container $container)
62: {
63: // This method is a stub. Reimplement in children template classes.
64: }
65:
66:
67: /**
68: * @param boolean $active The active flag.
69: * @return AbstractWidget Chainable
70: */
71: public function setActive($active)
72: {
73: $this->active = !!$active;
74: return $this;
75: }
76:
77: /**
78: * @return boolean
79: */
80: public function active()
81: {
82: return $this->active;
83: }
84: }
85: