File tree 2 files changed +34
-2
lines changed
lib/internal/Magento/Framework/View 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,18 @@ public function minify($file)
114
114
{
115
115
$ dir = dirname ($ file );
116
116
$ fileName = basename ($ file );
117
+ $ content = $ this ->readFactory ->create ($ dir )->readFile ($ fileName );
118
+ //Storing Heredocs
119
+ $ heredocs = [];
120
+ $ content = preg_replace_callback (
121
+ '/<<<([A-z]+).*?\1;/ims ' ,
122
+ function ($ match ) use (&$ heredocs ) {
123
+ $ heredocs [] = $ match [0 ];
124
+
125
+ return '__MINIFIED_HEREDOC__ ' .(count ($ heredocs ) - 1 );
126
+ },
127
+ $ content
128
+ );
117
129
$ content = preg_replace (
118
130
'#(?<!]]>)\s+</# ' ,
119
131
'</ ' ,
@@ -136,7 +148,7 @@ public function minify($file)
136
148
preg_replace (
137
149
'#(?<!:)//[^\n\r]*(\<\?php)[^\n\r]*(\s\?\>)[^\n\r]*# ' ,
138
150
'' ,
139
- $ this -> readFactory -> create ( $ dir )-> readFile ( $ fileName )
151
+ $ content
140
152
)
141
153
)
142
154
)
@@ -145,6 +157,15 @@ public function minify($file)
145
157
)
146
158
);
147
159
160
+ //Restoring Heredocs
161
+ $ content = preg_replace_callback (
162
+ '/__MINIFIED_HEREDOC__(\d+)/ims ' ,
163
+ function ($ match ) use ($ heredocs ) {
164
+ return $ heredocs [(int )$ match [1 ]];
165
+ },
166
+ $ content
167
+ );
168
+
148
169
if (!$ this ->htmlDirectory ->isExist ()) {
149
170
$ this ->htmlDirectory ->create ();
150
171
}
Original file line number Diff line number Diff line change @@ -113,6 +113,8 @@ public function testGetPathToMinified()
113
113
/**
114
114
* Covered method minify and test regular expressions
115
115
* @test
116
+ *
117
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
116
118
*/
117
119
public function testMinify ()
118
120
{
@@ -167,6 +169,12 @@ public function testMinify()
167
169
<?php // echo \$block->getChildHtml('anotherChildBlock'); ?>
168
170
<?php // endif; ?>
169
171
</body>
172
+ <?php
173
+ \$sometext = <<<SOMETEXT
174
+ mytext
175
+ mytextline2
176
+ SOMETEXT;
177
+ ?>
170
178
</html>
171
179
TEXT ;
172
180
@@ -189,7 +197,10 @@ public function testMinify()
189
197
}
190
198
});
191
199
//]]>
192
- </script><?php echo "http://some.link.com/" ?> <?php echo "//some.link.com/" ?> <?php echo '//some.link.com/' ?> <em>inline text</em> <a href="http://www.<?php echo 'hi' ?>"></a> <?php ?> <?php echo \$block->getChildHtml('someChildBlock'); ?> <?php ?> <?php ?> <?php ?></body></html>
200
+ </script><?php echo "http://some.link.com/" ?> <?php echo "//some.link.com/" ?> <?php echo '//some.link.com/' ?> <em>inline text</em> <a href="http://www.<?php echo 'hi' ?>"></a> <?php ?> <?php echo \$block->getChildHtml('someChildBlock'); ?> <?php ?> <?php ?> <?php ?></body><?php \$sometext = <<<SOMETEXT
201
+ mytext
202
+ mytextline2
203
+ SOMETEXT; ?></html>
193
204
TEXT ;
194
205
195
206
$ this ->appDirectoryMock ->expects ($ this ->once ())
You can’t perform that action at this time.
0 commit comments