|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Author: panosru |
|
7
|
|
|
* Date: 24/04/2018 |
|
8
|
|
|
* Time: 13:07 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Omega\FaultManager\Plugins; |
|
12
|
|
|
|
|
13
|
|
|
use League\Flysystem\FilesystemInterface as IFilesystemInterface; |
|
14
|
|
|
use League\Flysystem\PluginInterface as IPluginInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class CompiledExceptions |
|
18
|
|
|
* @package Omega\FaultManager\Plugins |
|
19
|
|
|
*/ |
|
20
|
|
|
class CompiledExceptions implements IPluginInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var bool */ |
|
23
|
|
|
public const RETURN_IN_ARRAY = true; |
|
24
|
|
|
|
|
25
|
|
|
/** @var bool */ |
|
26
|
|
|
public const RETURN_NOT_IN_ARRAY = false; |
|
27
|
|
|
|
|
28
|
|
|
/** @var IFilesystemInterface */ |
|
29
|
|
|
protected $filesystem; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param IFilesystemInterface $filesystem |
|
33
|
|
|
*/ |
|
34
|
|
|
public function setFilesystem(IFilesystemInterface $filesystem): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->filesystem = $filesystem; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getMethod(): string |
|
43
|
|
|
{ |
|
44
|
|
|
return 'compiledExceptions'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param array|null $filter |
|
49
|
|
|
* @param bool $whitelist |
|
50
|
|
|
* @return \Generator |
|
51
|
|
|
*/ |
|
52
|
|
|
public function handle(?array $filter = null, bool $whitelist = true): \Generator |
|
53
|
|
|
{ |
|
54
|
|
|
$path = \Omega\FaultManager\Fault::compilePath(); |
|
55
|
|
|
$files = $this->filesystem->listContents(); |
|
56
|
|
|
|
|
57
|
|
|
foreach ($files as $file) { |
|
58
|
|
|
// Check if the extension is php |
|
59
|
|
|
if (0 !== \strcmp('php', $file['extension'])) { |
|
60
|
|
|
continue; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
// If filter is set, then process filter |
|
64
|
|
|
if (null !== $filter) { |
|
65
|
|
|
// by default we process those that are in $filter array |
|
66
|
|
|
if ($whitelist && !\in_array($file['filename'], $filter, true)) { |
|
67
|
|
|
continue; |
|
68
|
|
|
} |
|
69
|
|
|
// if $whitelist is set to false, then we invert the processes |
|
70
|
|
|
if (!$whitelist && \in_array($file['filename'], $filter, true)) { |
|
71
|
|
|
continue; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
yield $path . $file['path']; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|