|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WebHemi. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 7.1 |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com) |
|
8
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
|
9
|
|
|
* |
|
10
|
|
|
* @link http://www.gixx-web.com |
|
11
|
|
|
*/ |
|
12
|
|
|
declare(strict_types = 1); |
|
13
|
|
|
|
|
14
|
|
|
namespace WebHemi\Renderer\Helper; |
|
15
|
|
|
|
|
16
|
|
|
use WebHemi\Environment\ServiceInterface as EnvironmentInterface; |
|
17
|
|
|
use WebHemi\Renderer\HelperInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class FileExistsHelper. |
|
21
|
|
|
*/ |
|
22
|
|
|
class FileExistsHelper implements HelperInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
private $applicationRoot; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Should return the name of the helper. |
|
29
|
|
|
* |
|
30
|
|
|
* @return string |
|
31
|
|
|
* @codeCoverageIgnore - plain text |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function getName() : string |
|
34
|
|
|
{ |
|
35
|
|
|
return 'fileExists'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Should return the name of the helper. |
|
40
|
|
|
* |
|
41
|
|
|
* @return string |
|
42
|
|
|
* @codeCoverageIgnore - plain text |
|
43
|
|
|
*/ |
|
44
|
|
|
public static function getDefinition() : string |
|
45
|
|
|
{ |
|
46
|
|
|
return '{% if fileExists("fileName") %}'; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Should return a description text. |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
* @codeCoverageIgnore - plain text |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function getDescription() : string |
|
56
|
|
|
{ |
|
57
|
|
|
return 'Checks if the given filepath exists under the application root.'; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Gets helper options for the render. |
|
62
|
|
|
* |
|
63
|
|
|
* @return array |
|
64
|
|
|
* @codeCoverageIgnore - empty array |
|
65
|
|
|
*/ |
|
66
|
|
|
public static function getOptions() : array |
|
67
|
|
|
{ |
|
68
|
|
|
return []; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* DefinedHelper constructor. |
|
73
|
|
|
* |
|
74
|
|
|
* @param EnvironmentInterface $environmentManager |
|
75
|
|
|
*/ |
|
76
|
|
|
public function __construct(EnvironmentInterface $environmentManager) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->applicationRoot = $environmentManager->getApplicationRoot(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* A renderer helper should be called with its name. |
|
83
|
|
|
* |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
|
|
public function __invoke() : bool |
|
87
|
|
|
{ |
|
88
|
|
|
$fileName = trim(func_get_args()[0], '/'); |
|
89
|
|
|
|
|
90
|
|
|
return file_exists($this->applicationRoot.'/'.$fileName); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|