File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2649,6 +2649,8 @@ protected function importFile($path, $out)
26492649 $ realPath = realpath ($ path );
26502650
26512651 if (isset ($ this ->importCache [$ realPath ])) {
2652+ $ this ->handleImportLoop ($ realPath );
2653+
26522654 $ tree = $ this ->importCache [$ realPath ];
26532655 } else {
26542656 $ code = file_get_contents ($ path );
@@ -2733,6 +2735,28 @@ public function throwError($msg)
27332735 throw new \Exception ($ msg );
27342736 }
27352737
2738+ /**
2739+ * Handle import loop
2740+ *
2741+ * @param string $name
2742+ *
2743+ * @throws \Exception
2744+ */
2745+ private function handleImportLoop ($ name )
2746+ {
2747+ for ($ env = $ this ->env ; $ env ; $ env = $ env ->parent ) {
2748+ $ file = $ env ->block ->sourceParser ->getSourceName ();
2749+
2750+ if (realpath ($ file ) === $ name ) {
2751+ $ this ->throwError (
2752+ 'An @import loop has been found: %s imports %s ' ,
2753+ $ this ->env ->block ->sourceParser ->getSourceName (),
2754+ basename ($ file )
2755+ );
2756+ }
2757+ }
2758+ }
2759+
27362760 /**
27372761 * Does file exist?
27382762 *
You can’t perform that action at this time.
0 commit comments