Skip to content

Commit 3dc741e

Browse files
committed
Merge branch 'develop'
2 parents e8a62ca + b040ba9 commit 3dc741e

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

find-usable-php.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@
55
//check for valet
66
//$use_valet = !empty(shell_exec('command -v valet'));
77
$use_valet = false;
8+
$use_ddev = false;
89

910
// First, check if the system's linked "php" is 7.4+; if so, return that. This
1011
// is the most likely, most ideal, and fastest possible case
1112
if ($use_valet) {
1213
$linkedPhpVersion = shell_exec('valet php -r "echo phpversion();"');
14+
} else if ($use_ddev) {
15+
$linkedPhpVersion = shell_exec('ddev php -r "echo phpversion();"');
1316
} else {
1417
$linkedPhpVersion = shell_exec('php -r "echo phpversion();"');
1518
}
1619

1720
if (version_compare($linkedPhpVersion, $minimumPhpVersion) >= 0) {
1821
if ($use_valet) {
1922
echo exec('valet php -dxdebug.remote_enable=true -dxdebug.mode=debug -dxdebug.start_with_request=yes -r \'echo $_SERVER["_"];\'');
23+
} else if ($use_ddev) {
24+
echo exec('ddev php -r \'echo $_SERVER["_"];\'');
2025
} else {
2126
echo exec('which php');
2227
}

src/Command/AbstractCommand.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ public function getAppConfig(bool $new = false)
8383
]
8484
]);
8585

86+
if ($this->isDdevSupported()) {
87+
// Replace internal DB hostname with external hostname
88+
$config->merge([
89+
'databases' => [
90+
$config->defaultDatabase() => [
91+
'hostname' => $this->getDdevDbHostname(),
92+
]
93+
]
94+
]);
95+
}
96+
8697
$this->appConfig = $config;
8798
}
8899

@@ -201,6 +212,10 @@ public function getPhpBinaryForCharcoal(OutputInterface $output)
201212
$phpBinary = $this->getPhpBinaryFromScript('cd ' . __DIR__ . '/../../;valet link;valet which-php', $output);
202213
}
203214

215+
if ($this->isDdevSupported()) {
216+
$phpBinary = 'ddev php';
217+
}
218+
204219
return $phpBinary;
205220
}
206221

@@ -221,6 +236,30 @@ public function isValetSupported()
221236
return !empty(shell_exec(sprintf("which %s", escapeshellarg('valet'))));
222237
}
223238

239+
public function isDdevSupported()
240+
{
241+
$path = $this->getProjectDir() . '/.ddev/.webimageBuild/Dockerfile';
242+
$dockerfile_exists = file_exists($path);
243+
$ddev_command_exists = !empty(shell_exec(sprintf("which %s", escapeshellarg('ddev'))));
244+
245+
return $dockerfile_exists && $ddev_command_exists;
246+
}
247+
248+
function getDdevDbHostname(): ?string {
249+
try {
250+
$ddevJson = json_decode(trim(shell_exec('ddev describe -j')), true);
251+
252+
$dbHost = $ddevJson['raw']['dbinfo']['host'];
253+
$dbHost = $dbHost === 'db' ? '127.0.0.1' : $dbHost;
254+
255+
$dbPort = $ddevJson['raw']['dbinfo']['published_port'];
256+
257+
return $dbHost . ':' . $dbPort;
258+
} catch (\Throwable $th) {
259+
//throw $th;
260+
}
261+
}
262+
224263
protected function getQuestionHelper(): QuestionHelper
225264
{
226265
return $this->getHelper('question');

0 commit comments

Comments
 (0)