@@ -11,15 +11,36 @@ class ContaoValetDriver extends ValetDriver
1111 */
1212 public function serves (string $ sitePath , string $ siteName , string $ uri ): bool
1313 {
14- return is_dir ($ sitePath .'/vendor/contao ' ) && file_exists ($ sitePath .'/web/app.php ' );
14+ $ frontControllerDirectory = $ this ->frontControllerDirectory ($ sitePath );
15+
16+ return is_dir ($ sitePath .'/vendor/contao ' ) && file_exists ($ sitePath .'/ ' .$ frontControllerDirectory .'/index.php ' );
17+ }
18+
19+ /**
20+ * Determine the name of the directory where the front controller lives.
21+ */
22+ public function frontControllerDirectory ($ sitePath ): string
23+ {
24+ $ dirs = ['web ' , 'public ' ];
25+
26+ foreach ($ dirs as $ dir ) {
27+ if (is_dir ($ sitePath .'/ ' .$ dir )) {
28+ return $ dir ;
29+ }
30+ }
31+
32+ // Give up, and just return the default
33+ return 'public ' ;
1534 }
1635
1736 /**
1837 * Determine if the incoming request is for a static file.
1938 */
2039 public function isStaticFile (string $ sitePath , string $ siteName , string $ uri )/* : string|false */
2140 {
22- if ($ this ->isActualFile ($ staticFilePath = $ sitePath .'/web ' .$ uri )) {
41+ $ frontControllerDirectory = $ this ->frontControllerDirectory ($ sitePath );
42+
43+ if ($ this ->isActualFile ($ staticFilePath = $ sitePath .'/ ' .$ frontControllerDirectory .$ uri )) {
2344 return $ staticFilePath ;
2445 }
2546
@@ -31,17 +52,21 @@ public function isStaticFile(string $sitePath, string $siteName, string $uri)/*
3152 */
3253 public function frontControllerPath (string $ sitePath , string $ siteName , string $ uri ): ?string
3354 {
34- if ($ uri === '/install.php ' ) {
35- return $ sitePath .'/web/install.php ' ;
55+ $ frontControllerDirectory = $ this ->frontControllerDirectory ($ sitePath );
56+
57+ if (strncmp ($ uri , '/contao-manager.phar.php ' , 24 ) === 0 ) {
58+ $ _SERVER ['SCRIPT_NAME ' ] = '/contao-manager.phar.php ' ;
59+ $ _SERVER ['SCRIPT_FILENAME ' ] = $ sitePath .'/contao-manager.phar.php ' ;
60+ return $ sitePath .'/ ' .$ frontControllerDirectory .'/contao-manager.phar.php ' ;
3661 }
3762
38- if (strncmp ($ uri , '/app_dev .php ' , 12 ) === 0 ) {
39- $ _SERVER ['SCRIPT_NAME ' ] = '/app_dev .php ' ;
40- $ _SERVER ['SCRIPT_FILENAME ' ] = $ sitePath .'/app_dev .php ' ;
63+ if (strncmp ($ uri , '/preview .php ' , 12 ) === 0 ) {
64+ $ _SERVER ['SCRIPT_NAME ' ] = '/preview .php ' ;
65+ $ _SERVER ['SCRIPT_FILENAME ' ] = $ sitePath .'/preview .php ' ;
4166
42- return $ sitePath .'/web/app_dev .php ' ;
67+ return $ sitePath .'/ ' . $ frontControllerDirectory . ' /preview .php ' ;
4368 }
4469
45- return $ sitePath .'/web/app .php ' ;
70+ return $ sitePath .'/ ' . $ frontControllerDirectory . ' /index .php ' ;
4671 }
4772}
0 commit comments