File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
lib/internal/Magento/Framework/View Expand file tree Collapse file tree 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)
114114 {
115115 $ dir = dirname ($ file );
116116 $ 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+ );
117129 $ content = preg_replace (
118130 '#(?<!]]>)\s+</# ' ,
119131 '</ ' ,
@@ -136,7 +148,7 @@ public function minify($file)
136148 preg_replace (
137149 '#(?<!:)//[^\n\r]*(\<\?php)[^\n\r]*(\s\?\>)[^\n\r]*# ' ,
138150 '' ,
139- $ this -> readFactory -> create ( $ dir )-> readFile ( $ fileName )
151+ $ content
140152 )
141153 )
142154 )
@@ -145,6 +157,15 @@ public function minify($file)
145157 )
146158 );
147159
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+
148169 if (!$ this ->htmlDirectory ->isExist ()) {
149170 $ this ->htmlDirectory ->create ();
150171 }
Original file line number Diff line number Diff line change @@ -113,6 +113,8 @@ public function testGetPathToMinified()
113113 /**
114114 * Covered method minify and test regular expressions
115115 * @test
116+ *
117+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
116118 */
117119 public function testMinify ()
118120 {
@@ -167,6 +169,12 @@ public function testMinify()
167169 <?php // echo \$block->getChildHtml('anotherChildBlock'); ?>
168170 <?php // endif; ?>
169171 </body>
172+ <?php
173+ \$sometext = <<<SOMETEXT
174+ mytext
175+ mytextline2
176+ SOMETEXT;
177+ ?>
170178</html>
171179TEXT ;
172180
@@ -189,7 +197,10 @@ public function testMinify()
189197 }
190198 });
191199 //]]>
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>
193204TEXT ;
194205
195206 $ this ->appDirectoryMock ->expects ($ this ->once ())
You can’t perform that action at this time.
0 commit comments