Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 44 |
|
0.00% |
0 / 26 |
CRAP | |
0.00% |
0 / 1 |
| FtpStorage | |
0.00% |
0 / 44 |
|
0.00% |
0 / 26 |
1332 | |
0.00% |
0 / 1 |
| with | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getClassType | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| put | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| get | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| create | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| list | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| set | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| append | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| prepend | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| extension | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| created | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| changed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| owner | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| permission | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| parent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| delete | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| copy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| move | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| size | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| exists | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| name | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| basename | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| dirname | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| dirpath | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| count | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| sanitize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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\System\File\PathException; |
| 18 | use phpOMS\System\File\StorageAbstract; |
| 19 | |
| 20 | /** |
| 21 | * Filesystem class. |
| 22 | * |
| 23 | * Performing operations on the file system |
| 24 | * |
| 25 | * @package phpOMS\System\File\Ftp |
| 26 | * @license OMS License 2.0 |
| 27 | * @link https://jingga.app |
| 28 | * @since 1.0.0 |
| 29 | */ |
| 30 | class FtpStorage extends StorageAbstract |
| 31 | { |
| 32 | /** |
| 33 | * Connection |
| 34 | * |
| 35 | * @var \FTP\Connection |
| 36 | * @since 1.0.0 |
| 37 | */ |
| 38 | private static \FTP\Connection $con; |
| 39 | |
| 40 | /** |
| 41 | * Set connection |
| 42 | * |
| 43 | * @param \FTP\Connection $con Connection |
| 44 | * |
| 45 | * @return void |
| 46 | * |
| 47 | * @since 1.0.0 |
| 48 | */ |
| 49 | public static function with(\FTP\Connection $con) : void |
| 50 | { |
| 51 | self::$con = $con; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * {@inheritdoc} |
| 56 | */ |
| 57 | protected static function getClassType(string $path) : string |
| 58 | { |
| 59 | return \ftp_size(self::$con, $path) === -1 && \stripos($path, '.') === false |
| 60 | ? Directory::class |
| 61 | : File::class; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * {@inheritdoc} |
| 66 | * |
| 67 | * @throws PathException |
| 68 | */ |
| 69 | public static function put(string $path, string $content, int $mode = 0) : bool |
| 70 | { |
| 71 | if (static::getClassType($path) === Directory::class) { |
| 72 | throw new PathException($path); |
| 73 | } |
| 74 | |
| 75 | return File::put(self::$con, $path, $content, $mode); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * {@inheritdoc} |
| 80 | * |
| 81 | * @throws PathException |
| 82 | */ |
| 83 | public static function get(string $path) : string |
| 84 | { |
| 85 | if (static::getClassType($path) === Directory::class) { |
| 86 | throw new PathException($path); |
| 87 | } |
| 88 | |
| 89 | return File::get(self::$con, $path); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * {@inheritdoc} |
| 94 | */ |
| 95 | public static function create(string $path) : bool |
| 96 | { |
| 97 | return \stripos($path, '.') === false |
| 98 | ? Directory::create(self::$con, $path, 0755, true) |
| 99 | : File::create(self::$con, $path); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * {@inheritdoc} |
| 104 | * |
| 105 | * @throws PathException |
| 106 | */ |
| 107 | public static function list(string $path, string $filter = '*', bool $recursive = false) : array |
| 108 | { |
| 109 | if (static::getClassType($path) === File::class) { |
| 110 | throw new PathException($path); |
| 111 | } |
| 112 | |
| 113 | return Directory::list(self::$con, $path, $filter, $recursive); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * {@inheritdoc} |
| 118 | * |
| 119 | * @throws PathException |
| 120 | */ |
| 121 | public static function set(string $path, string $content) : bool |
| 122 | { |
| 123 | if (static::getClassType($path) === Directory::class) { |
| 124 | throw new PathException($path); |
| 125 | } |
| 126 | |
| 127 | return File::set(self::$con, $path, $content); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * {@inheritdoc} |
| 132 | * |
| 133 | * @throws PathException |
| 134 | */ |
| 135 | public static function append(string $path, string $content) : bool |
| 136 | { |
| 137 | if (static::getClassType($path) === Directory::class) { |
| 138 | throw new PathException($path); |
| 139 | } |
| 140 | |
| 141 | return File::append(self::$con, $path, $content); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * {@inheritdoc} |
| 146 | * |
| 147 | * @throws PathException |
| 148 | */ |
| 149 | public static function prepend(string $path, string $content) : bool |
| 150 | { |
| 151 | if (static::getClassType($path) === Directory::class) { |
| 152 | throw new PathException($path); |
| 153 | } |
| 154 | |
| 155 | return File::prepend(self::$con, $path, $content); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * {@inheritdoc} |
| 160 | * |
| 161 | * @throws PathException |
| 162 | */ |
| 163 | public static function extension(string $path) : string |
| 164 | { |
| 165 | if (static::getClassType($path) === Directory::class) { |
| 166 | throw new PathException($path); |
| 167 | } |
| 168 | |
| 169 | return File::extension($path); |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * {@inheritdoc} |
| 174 | */ |
| 175 | public static function created(string $path) : \DateTime |
| 176 | { |
| 177 | return static::getClassType($path)::created(self::$con, $path); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * {@inheritdoc} |
| 182 | */ |
| 183 | public static function changed(string $path) : \DateTime |
| 184 | { |
| 185 | return static::getClassType($path)::changed(self::$con, $path); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * {@inheritdoc} |
| 190 | */ |
| 191 | public static function owner(string $path) : int |
| 192 | { |
| 193 | return static::getClassType($path)::owner(self::$con, $path); |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * {@inheritdoc} |
| 198 | */ |
| 199 | public static function permission(string $path) : int |
| 200 | { |
| 201 | return static::getClassType($path)::permission(self::$con, $path); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * {@inheritdoc} |
| 206 | */ |
| 207 | public static function parent(string $path) : string |
| 208 | { |
| 209 | return static::getClassType($path)::parent($path); |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * {@inheritdoc} |
| 214 | */ |
| 215 | public static function delete(string $path) : bool |
| 216 | { |
| 217 | return static::getClassType($path)::delete(self::$con, $path); |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * {@inheritdoc} |
| 222 | */ |
| 223 | public static function copy(string $from, string $to, bool $overwrite = false) : bool |
| 224 | { |
| 225 | return static::getClassType($from)::copy(self::$con, $from, $to, $overwrite); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * {@inheritdoc} |
| 230 | */ |
| 231 | public static function move(string $from, string $to, bool $overwrite = false) : bool |
| 232 | { |
| 233 | return static::getClassType($from)::move(self::$con, $from, $to, $overwrite); |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * {@inheritdoc} |
| 238 | */ |
| 239 | public static function size(string $path, bool $recursive = true) : int |
| 240 | { |
| 241 | return static::getClassType($path)::size(self::$con, $path, $recursive); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * {@inheritdoc} |
| 246 | */ |
| 247 | public static function exists(string $path) : bool |
| 248 | { |
| 249 | return static::getClassType($path)::exists(self::$con, $path); |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * {@inheritdoc} |
| 254 | */ |
| 255 | public static function name(string $path) : string |
| 256 | { |
| 257 | return static::getClassType($path)::name($path); |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * {@inheritdoc} |
| 262 | */ |
| 263 | public static function basename(string $path) : string |
| 264 | { |
| 265 | return static::getClassType($path)::basename($path); |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * {@inheritdoc} |
| 270 | */ |
| 271 | public static function dirname(string $path) : string |
| 272 | { |
| 273 | return static::getClassType($path)::dirname($path); |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * {@inheritdoc} |
| 278 | */ |
| 279 | public static function dirpath(string $path) : string |
| 280 | { |
| 281 | return static::getClassType($path)::dirpath($path); |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * {@inheritdoc} |
| 286 | */ |
| 287 | public static function count(string $path, bool $recursive = true, array $ignore = []) : int |
| 288 | { |
| 289 | return static::getClassType($path)::count(self::$con, $path, $recursive, $ignore); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * {@inheritdoc} |
| 294 | */ |
| 295 | public static function sanitize(string $path, string $replace = '', string $invalid = '/[^\w\s\d\.\-_~,;\/\[\]\(\]]/') : string |
| 296 | { |
| 297 | return static::getClassType($path)::sanitize($path, $replace); |
| 298 | } |
| 299 | } |