Skip to content

Commit 0177d73

Browse files
authored
Merge pull request #1532 from lukasbableck/contao-driver
Update `ContaoValetDriver` to support current Contao versions
2 parents 1add455 + ed8ca45 commit 0177d73

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

cli/Valet/Drivers/Specific/ContaoValetDriver.php

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

tests/Drivers/ContaoValetDriverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ public function test_it_gets_front_controller()
2323
$driver = new ContaoValetDriver;
2424

2525
$projectPath = $this->projectDir('contao');
26-
$this->assertEquals($projectPath.'/web/app.php', $driver->frontControllerPath($projectPath, 'my-site', '/'));
26+
$this->assertEquals($projectPath.'/public/index.php', $driver->frontControllerPath($projectPath, 'my-site', '/'));
2727
}
2828
}
File renamed without changes.

0 commit comments

Comments
 (0)