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: // PSR-7 (HTTP Messaging) dependencies
10: use \Psr\Http\Message\RequestInterface;
11:
12: // Dependencies from `Pimple`
13: use \Pimple\Container;
14:
15: // Module `charcoal-config` dependencies
16: use \Charcoal\Config\AbstractEntity;
17:
18: // Intra-module (`charcoal-app`) dependencies
19: use \Charcoal\App\Template\TemplateInterface;
20:
21: /**
22: * Template (View Controller) base class
23: */
24: abstract class AbstractTemplate extends AbstractEntity implements
25: LoggerAwareInterface,
26: TemplateInterface
27: {
28: use LoggerAwareTrait;
29:
30: /**
31: * @param array|\ArrayAccess $data The dependencies (app and logger).
32: */
33: public function __construct($data = null)
34: {
35: $this->setLogger($data['logger']);
36:
37: if (isset($data['container'])) {
38: $this->setDependencies($data['container']);
39: }
40: }
41:
42: /**
43: * Initialize the template with a request.
44: *
45: * @param RequestInterface $request The request to intialize.
46: * @return boolean Success / Failure.
47: */
48: public function init(RequestInterface $request)
49: {
50: // This method is a stub. Reimplement in children methods to ensure template initialization.
51: return true;
52: }
53:
54: /**
55: * Give an opportunity to children classes to inject dependencies from a Pimple Container.
56: *
57: * Does nothing by default, reimplement in children classes.
58: *
59: * The `$container` DI-container (from `Pimple`) should not be saved or passed around, only to be used to
60: * inject dependencies (typically via setters).
61: *
62: * @param Container $container A dependencies container instance.
63: * @return void
64: */
65: public function setDependencies(Container $container)
66: {
67: // This method is a stub. Reimplement in children template classes.
68: }
69: }
70: