|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************************** |
|
3
|
|
|
* An iterator interface over the Leagues flysystem. |
|
4
|
|
|
* Copyright (c) 2021, 2015 Richard Klees <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This software is licensed under GPLv3. You should have received |
|
7
|
|
|
* a copy of the along with the code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Lechimp\Flightcontrol; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Some object on the filesystem. |
|
14
|
|
|
*/ |
|
15
|
|
|
abstract class FSObject |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var Flightcontrol |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $flightcontrol; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \League\Flysystem\Filesystem |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $filesystem; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $path; |
|
31
|
|
|
|
|
32
|
66 |
|
public function __construct(Flightcontrol $flightcontrol, string $path) |
|
33
|
|
|
{ |
|
34
|
66 |
|
assert(is_string($path)); |
|
35
|
66 |
|
$this->flightcontrol = $flightcontrol; |
|
36
|
66 |
|
$this->path = self::normalize($path); |
|
37
|
66 |
|
} |
|
38
|
|
|
|
|
39
|
45 |
|
public function flightcontrol() : Flightcontrol |
|
40
|
|
|
{ |
|
41
|
45 |
|
return $this->flightcontrol; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
52 |
|
public function filesystem() : \League\Flysystem\Filesystem |
|
45
|
|
|
{ |
|
46
|
52 |
|
return $this->flightcontrol->filesystem(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
58 |
|
public function path() : string |
|
50
|
|
|
{ |
|
51
|
58 |
|
return $this->path; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
52 |
|
public function name() : string |
|
55
|
|
|
{ |
|
56
|
52 |
|
$parts = explode("/", $this->path); |
|
57
|
52 |
|
return end($parts); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function mimetype() : ?string |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->filesystem->mimetype($this->path); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
// Helper |
|
66
|
|
|
|
|
67
|
66 |
|
private static function normalize(string $path) : string |
|
68
|
|
|
{ |
|
69
|
66 |
|
if (substr($path, -1) == "/") { |
|
70
|
3 |
|
$path = substr($path, 0, strlen($path) - 1); |
|
71
|
|
|
} |
|
72
|
66 |
|
return $path; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
abstract public function isFile() : bool; |
|
76
|
|
|
} |
|
77
|
|
|
|