1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Models\SmartProperties\Properties\Definitions\Traits; |
4
|
|
|
|
5
|
|
|
use Nip\Utility\Str; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Trait HasItemsDirectoryTrait |
9
|
|
|
* @package ByTIC\Models\SmartProperties\Properties\Definitions\Traits |
10
|
|
|
*/ |
11
|
|
|
trait HasItemsDirectoryTrait |
12
|
|
|
{ |
13
|
|
|
protected $itemsDirectory = null; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @return null|string |
18
|
|
|
*/ |
19
|
17 |
|
public function getItemsDirectory() |
20
|
|
|
{ |
21
|
17 |
|
if ($this->itemsDirectory == null) { |
22
|
16 |
|
$this->initItemsDirectory(); |
23
|
|
|
} |
24
|
|
|
|
25
|
17 |
|
return $this->itemsDirectory; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param $dir |
30
|
|
|
*/ |
31
|
17 |
|
public function setItemsDirectory($dir) |
32
|
|
|
{ |
33
|
17 |
|
$this->itemsDirectory = $dir; |
34
|
17 |
|
} |
35
|
|
|
|
36
|
16 |
|
protected function initItemsDirectory() |
37
|
|
|
{ |
38
|
16 |
|
$this->setItemsDirectory($this->generateItemsDirectory()); |
39
|
16 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
16 |
|
protected function generateItemsDirectory() |
45
|
|
|
{ |
46
|
16 |
|
$methodName = 'get' . $this->getName() . 'ItemsDirectory'; |
|
|
|
|
47
|
16 |
|
if (method_exists($this->getManager(), $methodName)) { |
|
|
|
|
48
|
|
|
return $this->getManager()->$methodName(); |
49
|
|
|
} |
50
|
|
|
|
51
|
16 |
|
$methodName = 'get' . Str::plural($this->getName()) . 'Directory'; |
52
|
16 |
|
if (method_exists($this->getManager(), $methodName)) { |
53
|
4 |
|
return $this->getManager()->$methodName(); |
54
|
|
|
} |
55
|
|
|
|
56
|
12 |
|
return $this->generateManagerDirectory() . DIRECTORY_SEPARATOR . $this->generatePropertyDirectory(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
12 |
|
protected function generateManagerDirectory() |
63
|
|
|
{ |
64
|
12 |
|
$reflector = new \ReflectionObject($this->getManager()); |
65
|
|
|
|
66
|
12 |
|
return dirname($reflector->getFileName()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
12 |
|
protected function generatePropertyDirectory() |
73
|
|
|
{ |
74
|
12 |
|
return $this->getLabel(); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|