1: <?php
2:
3: namespace Charcoal\Property;
4:
5: use PDO;
6:
7: use RuntimeException;
8: use InvalidArgumentException;
9:
10: // From Pimple
11: use Pimple\Container;
12:
13: // From 'charcoal-property'
14: use Charcoal\Property\AbstractProperty;
15: use Charcoal\Property\SelectablePropertyInterface;
16: use Charcoal\Property\SelectablePropertyTrait;
17:
18: /**
19: * Template Selector Property
20: */
21: class TemplateProperty extends AbstractProperty implements SelectablePropertyInterface
22: {
23: use SelectablePropertyTrait;
24:
25: /**
26: * Inject dependencies from a DI Container.
27: *
28: * @param Container $container A dependencies container instance.
29: * @return void
30: */
31: public function setDependencies(Container $container)
32: {
33: parent::setDependencies($container);
34:
35: $this->setChoices($container['config']['templates']);
36: }
37:
38: /**
39: * @return string
40: */
41: public function type()
42: {
43: return 'template';
44: }
45:
46: /**
47: * Retrieve the selected template's fully-qualified class name.
48: *
49: * @return string|null
50: */
51: public function __toString()
52: {
53: $val = $this->val();
54: $tpl = $this->choice($val);
55:
56: if (isset($tpl['class'])) {
57: return $tpl['class'];
58: }
59:
60: return null;
61: }
62:
63: /**
64: * @return string
65: */
66: public function sqlExtra()
67: {
68: return '';
69: }
70:
71: /**
72: * Get the SQL type (Storage format)
73: *
74: * Stored as `VARCHAR` for maxLength under 255 and `TEXT` for other, longer strings
75: *
76: * @return string The SQL type
77: */
78: public function sqlType()
79: {
80: // Multiple strings are always stored as TEXT because they can hold multiple values
81: if ($this->multiple()) {
82: return 'TEXT';
83: }
84:
85: return 'VARCHAR(255)';
86: }
87:
88: /**
89: * @return integer
90: */
91: public function sqlPdoType()
92: {
93: return PDO::PARAM_STR;
94: }
95: }
96: