1: <?php
2:
3: namespace Charcoal\Ui;
4:
5: use InvalidArgumentException;
6:
7: // From 'charcoa-config'
8: use Charcoal\Config\AbstractConfig;
9:
10: /**
11: * A UI Item configuration set.
12: */
13: class UiItemConfig extends AbstractConfig
14: {
15: /**
16: * The UI item type.
17: *
18: * @var string|null
19: */
20: private $type;
21:
22: /**
23: * The UI item's template.
24: *
25: * @var string|null
26: */
27: private $template;
28:
29: /**
30: * The FQN of a view controller.
31: *
32: * @var string|null
33: */
34: private $controller;
35:
36: /**
37: * Set the UI item type.
38: *
39: * The type of UI item (e.g., dashboard, layout, form, form group,
40: * field set, field, menu, menu item).
41: *
42: * @param string|null $type The UI item type.
43: * @throws InvalidArgumentException If the type is not a string.
44: * @return UiItemConfig Chainable
45: */
46: public function setType($type)
47: {
48: if (is_string($type) || $type === null) {
49: $this->type = $type;
50: } else {
51: throw new InvalidArgumentException(
52: 'Can not set UI item config type: Type must be a string or NULL'
53: );
54: }
55:
56: return $this;
57: }
58:
59: /**
60: * Retrieve the UI item type.
61: *
62: * @return string
63: */
64: public function type()
65: {
66: return $this->type;
67: }
68:
69: /**
70: * Set the UI item's template.
71: *
72: * Usually, a path to a file containing the template to be rendered.
73: *
74: * @param string $template A template (identifier).
75: * @throws InvalidArgumentException If the template is not a string.
76: * @return UiItemInterface Chainable
77: */
78: public function setTemplate($template)
79: {
80: if (!is_string($template)) {
81: throw new InvalidArgumentException(
82: 'The UI Item Config can not set the template, must be a string'
83: );
84: }
85:
86: $this->template = $template;
87:
88: return $this;
89: }
90:
91: /**
92: * Retrieve the UI item's template.
93: *
94: * @return string If unset, returns the UI item type.
95: */
96: public function template()
97: {
98: if ($this->template === null) {
99: return $this->type();
100: }
101:
102: return $this->template;
103: }
104:
105: /**
106: * Set the UI item's view controller "type" (identifier).
107: *
108: * @param string $controller The FQN of a view controller.
109: * @throws InvalidArgumentException If the controller is not a string.
110: * @return UiItemInterface Chainable
111: */
112: public function setController($controller)
113: {
114: if (!is_string($controller)) {
115: throw new InvalidArgumentException(
116: 'The UI Item Config can not set the view controller, must be a string'
117: );
118: }
119:
120: $this->controller = $controller;
121:
122: return $this;
123: }
124:
125: /**
126: * Retrieve the UI item's view controller "type" (identifier).
127: *
128: * @return string If unset, returns the UI item type.
129: */
130: public function controller()
131: {
132: if ($this->controller === null) {
133: return $this->type();
134: }
135:
136: return $this->controller;
137: }
138: }
139: