Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
FileAbstract | |
0.00% |
0 / 22 |
|
0.00% |
0 / 11 |
210 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getCount | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getBasename | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPath | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCreatedAt | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getChangedAt | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOwner | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPermission | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
index | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package phpOMS\System\File\Ftp |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\System\File\Ftp; |
16 | |
17 | use phpOMS\Uri\HttpUri; |
18 | |
19 | /** |
20 | * Filesystem class. |
21 | * |
22 | * Performing operations on the file system |
23 | * |
24 | * @package phpOMS\System\File\Ftp |
25 | * @license OMS License 2.0 |
26 | * @link https://jingga.app |
27 | * @since 1.0.0 |
28 | */ |
29 | abstract class FileAbstract implements FtpContainerInterface |
30 | { |
31 | /** |
32 | * Ftp connection |
33 | * |
34 | * @var null|\FTP\Connection |
35 | * @since 1.0.0 |
36 | */ |
37 | protected ?\FTP\Connection $con = null; |
38 | |
39 | /** |
40 | * Ftp uri |
41 | * |
42 | * @var HttpUri |
43 | * @since 1.0.0 |
44 | */ |
45 | protected HttpUri $uri; |
46 | |
47 | /** |
48 | * Path. |
49 | * |
50 | * @var string |
51 | * @since 1.0.0 |
52 | */ |
53 | protected string $path = ''; |
54 | |
55 | /** |
56 | * Name. |
57 | * |
58 | * @var string |
59 | * @since 1.0.0 |
60 | */ |
61 | protected string $name = 'new_directory'; |
62 | |
63 | /** |
64 | * Directory/File count. |
65 | * |
66 | * @var int |
67 | * @since 1.0.0 |
68 | */ |
69 | protected int $count = 0; |
70 | |
71 | /** |
72 | * Directory/Filesize in bytes. |
73 | * |
74 | * @var int |
75 | * @since 1.0.0 |
76 | */ |
77 | protected int $size = 0; |
78 | |
79 | /** |
80 | * Created at. |
81 | * |
82 | * @var \DateTimeImmutable |
83 | * @since 1.0.0 |
84 | */ |
85 | protected \DateTimeImmutable $createdAt; |
86 | |
87 | /** |
88 | * Last changed at. |
89 | * |
90 | * @var \DateTime |
91 | * @since 1.0.0 |
92 | */ |
93 | protected \DateTime $changedAt; |
94 | |
95 | /** |
96 | * Owner. |
97 | * |
98 | * @var string |
99 | * @since 1.0.0 |
100 | */ |
101 | protected string $owner = ''; |
102 | |
103 | /** |
104 | * Permission. |
105 | * |
106 | * @var int |
107 | * @since 1.0.0 |
108 | */ |
109 | protected int $permission = 0755; |
110 | |
111 | /** |
112 | * Is directory initialized |
113 | * |
114 | * @var bool |
115 | * @since 1.0.0 |
116 | */ |
117 | protected bool $isInitialized = false; |
118 | |
119 | /** |
120 | * Constructor. |
121 | * |
122 | * @param string $path Path |
123 | * |
124 | * @since 1.0.0 |
125 | */ |
126 | public function __construct(string $path) |
127 | { |
128 | $this->path = \rtrim($path, '/\\'); |
129 | $this->name = \basename($path); |
130 | |
131 | $this->createdAt = new \DateTimeImmutable('now'); |
132 | $this->changedAt = new \DateTime('now'); |
133 | } |
134 | |
135 | /** |
136 | * {@inheritdoc} |
137 | */ |
138 | public function getCount(bool $recursive = true) : int |
139 | { |
140 | return $this->count; |
141 | } |
142 | |
143 | /** |
144 | * {@inheritdoc} |
145 | */ |
146 | public function getSize(bool $recursive = true) : int |
147 | { |
148 | return $this->size; |
149 | } |
150 | |
151 | /** |
152 | * {@inheritdoc} |
153 | */ |
154 | public function getName() : string |
155 | { |
156 | return $this->name; |
157 | } |
158 | |
159 | /** |
160 | * {@inheritdoc} |
161 | */ |
162 | public function getBasename() : string |
163 | { |
164 | return \basename($this->path); |
165 | } |
166 | |
167 | /** |
168 | * {@inheritdoc} |
169 | */ |
170 | public function getPath() : string |
171 | { |
172 | return $this->path; |
173 | } |
174 | |
175 | /** |
176 | * {@inheritdoc} |
177 | */ |
178 | public function getCreatedAt() : \DateTimeImmutable |
179 | { |
180 | return $this->createdAt; |
181 | } |
182 | |
183 | /** |
184 | * {@inheritdoc} |
185 | */ |
186 | public function getChangedAt() : \DateTime |
187 | { |
188 | return $this->changedAt; |
189 | } |
190 | |
191 | /** |
192 | * {@inheritdoc} |
193 | */ |
194 | public function getOwner() : string |
195 | { |
196 | return $this->owner; |
197 | } |
198 | |
199 | /** |
200 | * {@inheritdoc} |
201 | */ |
202 | public function getPermission() : int |
203 | { |
204 | return $this->permission; |
205 | } |
206 | |
207 | /** |
208 | * {@inheritdoc} |
209 | */ |
210 | public function index() : void |
211 | { |
212 | if ($this->con === null) { |
213 | return; |
214 | } |
215 | |
216 | $mtime = \ftp_mdtm($this->con, $this->path); |
217 | $ctime = \ftp_mdtm($this->con, $this->path); |
218 | |
219 | $this->createdAt = (new \DateTimeImmutable())->setTimestamp($mtime === false ? 0 : $mtime); |
220 | $this->changedAt->setTimestamp($ctime === false ? 0 : $ctime); |
221 | |
222 | $this->owner = ''; |
223 | $this->permission = 0; |
224 | |
225 | $this->isInitialized = true; |
226 | } |
227 | } |