@@ -53,6 +53,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
53
53
protected $ bundleMap ;
54
54
protected $ container ;
55
55
protected $ rootDir ;
56
+ protected $ realRootDir ;
56
57
protected $ environment ;
57
58
protected $ debug ;
58
59
protected $ booted ;
@@ -731,24 +732,17 @@ private function removeAbsolutePathsFromContainer($content)
731
732
return $ content ;
732
733
}
733
734
734
- // find the "real" root dir (by finding the composer.json file)
735
- $ rootDir = $ this ->getRootDir ();
736
- $ previous = $ rootDir ;
737
- while (!file_exists ($ rootDir .'/composer.json ' )) {
738
- if ($ previous === $ rootDir = realpath ($ rootDir .'/.. ' )) {
739
- // unable to detect the project root, give up
740
- return $ content ;
741
- }
742
-
743
- $ previous = $ rootDir ;
735
+ $ rootDir = $ this ->getRealRootDir ();
736
+ if (!$ rootDir ) {
737
+ return $ content ;
744
738
}
745
739
746
740
$ rootDir = rtrim ($ rootDir , '/ ' );
747
741
$ cacheDir = $ this ->getCacheDir ();
748
742
$ filesystem = new Filesystem ();
749
743
750
- return preg_replace_callback ("{'([^']*)( " .preg_quote ($ rootDir )."[^']*)'} " , function ($ match ) use ($ filesystem , $ cacheDir ) {
751
- $ prefix = isset ($ match [1 ]) && $ match [ 1 ] ? "' $ match [1 ]'.__DIR__ " : "__DIR__ " ;
744
+ return preg_replace_callback ("{'([^']*? )( " .preg_quote ($ rootDir )."[^']*)'} " , function ($ match ) use ($ filesystem , $ cacheDir ) {
745
+ $ prefix = ! empty ($ match [1 ]) ? "' $ match [1 ]'.__DIR__ " : "__DIR__ " ;
752
746
753
747
if ('. ' === $ relativePath = rtrim ($ filesystem ->makePathRelative ($ match [2 ], $ cacheDir ), '/ ' )) {
754
748
return $ prefix ;
@@ -758,6 +752,33 @@ private function removeAbsolutePathsFromContainer($content)
758
752
}, $ content );
759
753
}
760
754
755
+ /**
756
+ * Find the "real" root dir (by finding the composer.json file)
757
+ *
758
+ * @return null|string
759
+ */
760
+ private function getRealRootDir ()
761
+ {
762
+ if (null !== $ this ->realRootDir ) {
763
+ return $ this ->realRootDir ;
764
+ }
765
+
766
+ $ rootDir = $ this ->getRootDir ();
767
+ $ previous = $ rootDir ;
768
+ while (!file_exists ($ rootDir .'/composer.json ' )) {
769
+ if ($ previous === $ rootDir = realpath ($ rootDir .'/.. ' )) {
770
+ // unable to detect the project root, give up
771
+ return $ this ->realRootDir = false ;
772
+ }
773
+
774
+ $ previous = $ rootDir ;
775
+ }
776
+
777
+ $ this ->realRootDir = $ rootDir ;
778
+
779
+ return $ this ->realRootDir ;
780
+ }
781
+
761
782
/**
762
783
* Returns a loader for the container.
763
784
*
0 commit comments