@@ -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