|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2019. Volodymyr Hryvinskyi. All rights reserved. |
|
4
|
|
|
* @author: <mailto:[email protected]> |
|
5
|
|
|
* @github: <https://github.com/hryvinskyi> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Hryvinskyi\DeferJs\Model\PassesValidator\Validators; |
|
11
|
|
|
|
|
12
|
|
|
use Hryvinskyi\Base\Helper\ArrayHelper; |
|
13
|
|
|
use Hryvinskyi\Base\Helper\Json; |
|
14
|
|
|
use Hryvinskyi\DeferJs\Helper\Config; |
|
15
|
|
|
use Hryvinskyi\DeferJs\Model\PassesValidator\ValidatorInterface; |
|
16
|
|
|
use Magento\Framework\App\Request\Http as RequestHttp; |
|
17
|
|
|
use Magento\Framework\App\Response\Http; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class SkipScriptsByController |
|
21
|
|
|
*/ |
|
22
|
|
|
class SkipScriptsByController implements ValidatorInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var Config |
|
26
|
|
|
*/ |
|
27
|
|
|
private $config; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var RequestHttp |
|
31
|
|
|
*/ |
|
32
|
|
|
private $request; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* SkipScriptsByController constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param Config $config |
|
38
|
|
|
* @param RequestHttp $request |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct( |
|
41
|
|
|
Config $config, |
|
42
|
|
|
RequestHttp $request |
|
43
|
|
|
) { |
|
44
|
|
|
$this->config = $config; |
|
45
|
|
|
$this->request = $request; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Validator function, handle javascript or not |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $script |
|
52
|
|
|
* @param Http $http |
|
53
|
|
|
* |
|
54
|
|
|
* @return bool |
|
55
|
|
|
*/ |
|
56
|
|
|
public function validate(string $script, Http $http): bool |
|
57
|
|
|
{ |
|
58
|
|
|
$moduleName = $this->request->getModuleName(); |
|
59
|
|
|
$controller = $this->request->getControllerName(); |
|
60
|
|
|
$action = $this->request->getActionName(); |
|
61
|
|
|
|
|
62
|
|
|
$controllerFull = $moduleName . '_' . $controller . '_' . $action; |
|
63
|
|
|
$controllersConfig = Json::decode($this->config->getExcludeControllers()); |
|
64
|
|
|
$controllersConfig = ArrayHelper::getColumn($controllersConfig, 'controller', false); |
|
65
|
|
|
|
|
66
|
|
|
$return = false; |
|
67
|
|
|
|
|
68
|
|
|
if (in_array($controllerFull, $controllersConfig)) { |
|
69
|
|
|
$return = true; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $return; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|