|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Fabiang\ExceptionGenerator\Event; |
|
6
|
|
|
|
|
7
|
|
|
use DirectoryIterator; |
|
8
|
|
|
use Symfony\Contracts\EventDispatcher\Event; |
|
9
|
|
|
|
|
10
|
|
|
class FileEvent extends Event |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Namespace. |
|
14
|
|
|
*/ |
|
15
|
|
|
protected ?string $namespace = null; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* ParentExceptionDir. |
|
19
|
|
|
*/ |
|
20
|
|
|
protected ?string $parentExceptionDir = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Full file path. |
|
24
|
|
|
*/ |
|
25
|
|
|
protected string $file; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* File extension. |
|
29
|
|
|
*/ |
|
30
|
|
|
protected string $extension; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* basename of item. |
|
34
|
|
|
*/ |
|
35
|
|
|
protected string $basename; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* dirname of item. |
|
39
|
|
|
*/ |
|
40
|
|
|
protected string $dirname; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Item is an directory. |
|
44
|
|
|
*/ |
|
45
|
|
|
protected bool $isDir = false; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Cache of looped directories. |
|
49
|
|
|
*/ |
|
50
|
|
|
protected array $loopedDirectories = []; |
|
51
|
|
|
|
|
52
|
2 |
|
public function __construct(DirectoryIterator $file) |
|
53
|
|
|
{ |
|
54
|
2 |
|
$this->file = $file->getPathname(); |
|
55
|
2 |
|
$this->extension = $this->getFileExtension($file); |
|
56
|
2 |
|
$this->basename = $file->getBasename(); |
|
57
|
2 |
|
$this->dirname = $file->getPath(); |
|
58
|
2 |
|
$this->isDir = $file->isDir(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get found parentExceptionDirs |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getParentExceptionDir(): ?string |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->parentExceptionDir; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Set found parentExceptionDirs. |
|
71
|
|
|
*/ |
|
72
|
|
|
public function setParentExceptionDir(): void |
|
73
|
|
|
{ |
|
74
|
|
|
$this->parentExceptionDir = $this->dirname . '/Exception'; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Get found namespace |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function getNamespace(): ?string |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->namespace; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Set found namespace. |
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function setNamespace(?string $namespace): void |
|
89
|
|
|
{ |
|
90
|
1 |
|
$this->namespace = $namespace; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get full filename. |
|
95
|
|
|
*/ |
|
96
|
2 |
|
public function getFile(): string |
|
97
|
|
|
{ |
|
98
|
2 |
|
return $this->file; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get file extension. |
|
103
|
|
|
*/ |
|
104
|
2 |
|
public function getExtension(): string |
|
105
|
|
|
{ |
|
106
|
2 |
|
return $this->extension; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Get basename of item. |
|
111
|
|
|
*/ |
|
112
|
2 |
|
public function getBasename(): string |
|
113
|
|
|
{ |
|
114
|
2 |
|
return $this->basename; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Get dirname of item. |
|
119
|
|
|
*/ |
|
120
|
2 |
|
public function getDirname(): string |
|
121
|
|
|
{ |
|
122
|
2 |
|
return $this->dirname; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Is item an directory. |
|
127
|
|
|
*/ |
|
128
|
2 |
|
public function isDir(): bool |
|
129
|
|
|
{ |
|
130
|
2 |
|
return $this->isDir; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Compatiblity method for PHP versions not |
|
135
|
|
|
* supporting DirectoryIterator::getExtension |
|
136
|
|
|
*/ |
|
137
|
2 |
|
private function getFileExtension(DirectoryIterator $file): string |
|
138
|
|
|
{ |
|
139
|
2 |
|
return $file->getExtension(); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Get looped directories while iterating up path. |
|
144
|
|
|
*/ |
|
145
|
1 |
|
public function getLoopedDirectories(): array |
|
146
|
|
|
{ |
|
147
|
1 |
|
return $this->loopedDirectories; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Set looped directories while iterating up path. |
|
152
|
|
|
*/ |
|
153
|
1 |
|
public function setLoopedDirectories(array $loopedDirectories): void |
|
154
|
|
|
{ |
|
155
|
1 |
|
$this->loopedDirectories = $loopedDirectories; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|