1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Automation tool mixed with code generator for easier continuous development |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hidev |
6
|
|
|
* @package hidev |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hidev\handlers; |
12
|
|
|
|
13
|
|
|
use hidev\helpers\FileHelper; |
14
|
|
|
use Yii; |
15
|
|
|
use yii\base\InvalidConfigException; |
16
|
|
|
use yii\helpers\ArrayHelper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Base Handler. |
20
|
|
|
* Knows how to parse and render it's file type. |
21
|
|
|
*/ |
22
|
|
|
class BaseHandler extends \yii\base\BaseObject |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var Goal |
|
|
|
|
26
|
|
|
*/ |
27
|
|
|
public $goal; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string template file name to be used for rendering |
31
|
|
|
*/ |
32
|
|
|
public $template; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var View object |
|
|
|
|
36
|
|
|
*/ |
37
|
|
|
protected $_view; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Returns the view object that can be used to render views or view files. |
41
|
|
|
* If not set, it will default to the "view" application component. |
42
|
|
|
* @return View the view object that can be used to render views or view files |
43
|
|
|
*/ |
44
|
|
|
public function getView() |
45
|
|
|
{ |
46
|
|
|
if ($this->_view === null) { |
47
|
|
|
$this->_view = Yii::$app->getView(); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $this->_view; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Renders prepared data. |
55
|
|
|
* Must be redefined in child. |
56
|
|
|
* @param array $data |
57
|
|
|
* @throws InvalidConfigException |
58
|
|
|
* @return string file content |
59
|
|
|
*/ |
60
|
|
|
public function renderPrepared(array $data) |
61
|
|
|
{ |
62
|
|
|
throw new InvalidConfigException('Render not available'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Renders raw data. |
67
|
|
|
* Prepares data with ArrayHelper::toArray. |
68
|
|
|
* @param mixed $data |
69
|
|
|
* @return string file content |
70
|
|
|
*/ |
71
|
|
|
public function render($data) |
72
|
|
|
{ |
73
|
|
|
return $this->renderPrepared($this->prepareData($data)); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function prepareData($data) |
77
|
|
|
{ |
78
|
|
|
return ArrayHelper::toArray($data, [], false); |
79
|
|
|
//return $data; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Renders file content using given data. |
84
|
|
|
* Converts to array with ArrayHelper::toArray. |
85
|
|
|
* @param mixed $data |
86
|
|
|
* @return string file content |
87
|
|
|
*/ |
88
|
3 |
|
public function renderPath($path, $data) |
89
|
|
|
{ |
90
|
3 |
|
return $this->write($path, $this->render($data)); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function parsePath($path, $minimal = null) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
return $this->parse($this->read($path)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Parses string input. To be redefined in real handlers. |
100
|
|
|
* @param string $input to parse |
101
|
|
|
* @return array |
102
|
|
|
*/ |
103
|
|
|
public function parse($input) |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
return []; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Writes given content to the file. |
110
|
|
|
* Doesn't touch file if it has exactly same content. |
111
|
|
|
* Creates intermediate directories when necessary. |
112
|
|
|
* @param string $path |
113
|
|
|
* @param string $content |
114
|
|
|
* @return bool true if file was changed |
115
|
|
|
*/ |
116
|
3 |
|
public function write($path, $content) |
117
|
|
|
{ |
118
|
3 |
|
return FileHelper::write($path, $content); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Creates directory if not exists. |
123
|
|
|
* @param string $path |
124
|
|
|
* @return bool true if directory did not exist and was created |
125
|
|
|
*/ |
126
|
|
|
public function mkdir($path) |
127
|
|
|
{ |
128
|
|
|
return FileHelper::mkdir($path); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Read file into a string or array. |
133
|
|
|
* @param string $path |
134
|
|
|
* @param bool $asArray |
135
|
|
|
* @return string|array |
136
|
|
|
*/ |
137
|
|
|
public function read($path, $asArray = false) |
138
|
|
|
{ |
139
|
|
|
if (file_exists($path)) { |
140
|
|
|
Yii::info('Read file: ' . $path, 'file'); |
141
|
|
|
|
142
|
|
|
return $asArray ? file($path) : file_get_contents($path); |
|
|
|
|
143
|
|
|
} else { |
144
|
|
|
Yii::warning('Couldn\'t read file: ' . $path, 'file'); |
145
|
|
|
|
146
|
|
|
return; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Read file into array of strings. |
152
|
|
|
* @param string $path |
153
|
|
|
* @return array |
154
|
|
|
*/ |
155
|
|
|
public function readArray($path) |
156
|
|
|
{ |
157
|
|
|
return $this->read($path, true); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths