1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Liip\MonitorBundle\Check; |
4
|
|
|
|
5
|
|
|
use Laminas\Diagnostics\Check\CheckInterface; |
6
|
|
|
use Laminas\Diagnostics\Result\Failure; |
7
|
|
|
use Laminas\Diagnostics\Result\Success; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Checks if error pages have been customized. |
11
|
|
|
* |
12
|
|
|
* @author Cédric Girard <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class CustomErrorPages implements CheckInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
protected $errorCodes; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $path; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $projectDir; |
30
|
|
|
|
31
|
1 |
|
public function __construct(array $errorCodes, $path, $projectDir) |
32
|
|
|
{ |
33
|
1 |
|
$this->errorCodes = $errorCodes; |
34
|
1 |
|
$this->path = $path; |
35
|
1 |
|
$this->projectDir = $projectDir; |
36
|
1 |
|
} |
37
|
|
|
|
38
|
|
|
public function check() |
39
|
|
|
{ |
40
|
|
|
$dir = $this->getCustomTemplateDirectory(); |
41
|
|
|
$missingTemplates = []; |
42
|
|
|
|
43
|
|
|
foreach ($this->errorCodes as $errorCode) { |
44
|
|
|
$template = sprintf('%s/error%d.html.twig', $dir, $errorCode); |
45
|
|
|
|
46
|
|
|
if (!file_exists($template)) { |
47
|
|
|
$missingTemplates[] = $errorCode; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if (count($missingTemplates) > 0) { |
52
|
|
|
return new Failure(sprintf('No custom error page found for the following codes: %s', implode(', ', $missingTemplates))); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return new Success(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getLabel() |
59
|
|
|
{ |
60
|
|
|
return 'Custom error pages'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
private function getCustomTemplateDirectory() |
67
|
|
|
{ |
68
|
|
|
if ($this->projectDir !== $this->path) { |
69
|
|
|
return $this->path; // using custom directory |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (file_exists($dir = $this->projectDir.'/templates/bundles/TwigBundle/Exception')) { |
73
|
|
|
return $dir; // using standard 4.0+ directory |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this->projectDir.'/app/Resources/TwigBundle/views/Exception'; // assume using 3.4 dir structure |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|