Total Complexity | 15 |
Total Lines | 136 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | trait HasPath |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * @var |
||
14 | */ |
||
15 | protected $name; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $path; |
||
21 | |||
22 | /** |
||
23 | * @var |
||
24 | */ |
||
25 | protected $url; |
||
26 | |||
27 | |||
28 | /** |
||
29 | * Set the entree path. |
||
30 | * |
||
31 | * @param string $path |
||
32 | * |
||
33 | * @return $this |
||
34 | */ |
||
35 | public function setPath(string $path) |
||
36 | { |
||
37 | $this->parseNameFromPath($path); |
||
38 | $this->path = $path; |
||
39 | |||
40 | return $this; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Retrieve the entree path. |
||
45 | * |
||
46 | * @return string path |
||
47 | */ |
||
48 | public function getPath(): string |
||
49 | { |
||
50 | if (!$this->path) { |
||
51 | $this->initPath(); |
||
52 | } |
||
53 | return $this->path; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @param string $name |
||
58 | * @return $this |
||
59 | */ |
||
60 | public function setFileName(string $name): self |
||
61 | { |
||
62 | $path_parts = pathinfo($this->getPath()); |
||
63 | $path_parts['filename'] = $name; |
||
64 | $this->setPath( |
||
65 | $path_parts['dirname'] |
||
66 | . '/' . $path_parts['filename'] . '.' . $path_parts['extension'] |
||
67 | ); |
||
68 | return $this; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @return string |
||
73 | */ |
||
74 | public function getPathFolder(): string |
||
75 | { |
||
76 | return '/'; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @return mixed |
||
81 | */ |
||
82 | public function getName() |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param string $name |
||
92 | * @return $this |
||
93 | */ |
||
94 | public function setName(string $name) : self |
||
95 | { |
||
96 | $this->name = $name; |
||
97 | return $this; |
||
98 | } |
||
99 | |||
100 | protected function initName() |
||
101 | { |
||
102 | $this->name = $this->getDefaultName(); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @return string |
||
107 | */ |
||
108 | public function getDefaultName(): string |
||
109 | { |
||
110 | return 'file'; |
||
111 | } |
||
112 | |||
113 | |||
114 | /** |
||
115 | * @return mixed |
||
116 | */ |
||
117 | public function getUrl() |
||
118 | { |
||
119 | if (!$this->url) { |
||
120 | $this->initUrl(); |
||
121 | } |
||
122 | return $this->url; |
||
123 | } |
||
124 | |||
125 | protected function initUrl() |
||
126 | { |
||
127 | $this->url = $this->getFilesystem()->getUrl($this->getPath()); |
||
|
|||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @param $path |
||
132 | */ |
||
133 | protected function parseNameFromPath($path) |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * @return void |
||
141 | */ |
||
142 | protected function initPath() |
||
145 | } |
||
146 | } |
||
147 |