1: <?php
2:
3: namespace Charcoal\Ui\Layout;
4:
5: use \InvalidArgumentException;
6:
7: use \Charcoal\Ui\Layout\LayoutBuilder;
8: use \Charcoal\Ui\Layout\LayoutInterface;
9:
10: 11: 12:
13: trait LayoutAwareTrait
14: {
15: 16: 17:
18: private $layout;
19:
20: 21: 22:
23: protected $layoutBuilder;
24:
25: 26: 27: 28:
29: public function setLayoutBuilder(LayoutBuilder $builder)
30: {
31: $this->layoutBuilder = $builder;
32: return $this;
33: }
34:
35: 36: 37: 38: 39:
40: public function setLayout($layout)
41: {
42: if (($layout instanceof LayoutInterface)) {
43: $this->layout = $layout;
44: } elseif (is_array($layout)) {
45: $this->layout = $this->layoutBuilder->build($layout);
46: } else {
47: throw new InvalidArgumentException(
48: 'Layout must be a LayoutInterface object or an array'
49: );
50: }
51: return $this;
52: }
53:
54: 55: 56:
57: public function layout()
58: {
59: return $this->layout;
60: }
61: }
62: