1: <?php
2:
3: namespace Deimos\Helper\Traits;
4:
5: use Deimos\Builder\Builder;
6: use Deimos\Helper\Helper as DeimosHelper;
7:
8: trait Helper
9: {
10:
11: /**
12: * @var Builder
13: */
14: protected $builder;
15:
16: /**
17: * @var DeimosHelper
18: */
19: private $helper;
20:
21: /**
22: * @return DeimosHelper
23: *
24: * @throws \InvalidArgumentException
25: */
26: private function instanceHelper()
27: {
28: if (method_exists($this->builder, 'helper'))
29: {
30: return $this->builder->helper();
31: }
32:
33: return new DeimosHelper($this->builder);
34: }
35:
36: /**
37: * @return DeimosHelper
38: *
39: * @throws \InvalidArgumentException
40: */
41: protected final function helper()
42: {
43: if (!$this->helper)
44: {
45: $this->helper = $this->instanceHelper();
46: }
47:
48: return $this->helper;
49: }
50:
51: }