|
4 | 4 |
|
5 | 5 | use Illuminate\Console\Command; |
6 | 6 | use Illuminate\Support\ConfigurationUrlParser; |
| 7 | +use Illuminate\Support\Uri; |
7 | 8 | use PDO; |
8 | 9 | use Symfony\Component\Console\Attribute\AsCommand; |
9 | 10 | use Symfony\Component\Process\Exception\ProcessFailedException; |
@@ -289,34 +290,17 @@ protected function buildDatabaseUrl(array $connection) |
289 | 290 | return $connection['database']; |
290 | 291 | } |
291 | 292 |
|
292 | | - $url = "{$driver}://"; |
293 | | - |
294 | | - if (! empty($connection['username'])) { |
295 | | - $url .= urlencode($connection['username']); |
296 | | - |
297 | | - if (! empty($connection['password'])) { |
298 | | - $url .= ':'.urlencode($connection['password']); |
299 | | - } |
300 | | - |
301 | | - $url .= '@'; |
302 | | - } |
303 | | - |
304 | | - $url .= $connection['host']; |
305 | | - |
306 | | - if (! empty($connection['port'])) { |
307 | | - $url .= ":{$connection['port']}"; |
308 | | - } |
309 | | - |
310 | | - if (! empty($connection['database'])) { |
311 | | - $url .= '/'.urlencode($connection['database']); |
312 | | - } |
313 | | - |
314 | | - $queryParams = $this->getQueryParameters($connection); |
315 | | - if (! empty($queryParams)) { |
316 | | - $url .= '?'.http_build_query($queryParams); |
317 | | - } |
318 | | - |
319 | | - return $url; |
| 293 | + return (new Uri) |
| 294 | + ->withScheme($driver) |
| 295 | + ->withHost($connection['host']) |
| 296 | + ->withUser( |
| 297 | + $connection['username'] ?? null, |
| 298 | + ! empty($connection['password']) ? $connection['password'] : null, |
| 299 | + ) |
| 300 | + ->when(! empty($connection['port']), fn (Uri $uri) => $uri->withPort((int) $connection['port'])) |
| 301 | + ->when(! empty($connection['database']), fn (Uri $uri) => $uri->withPath($connection['database'])) |
| 302 | + ->when(! empty($this->getQueryParameters($connection)), fn (Uri $uri) => $uri->withQuery($this->getQueryParameters($connection))) |
| 303 | + ->value(); |
320 | 304 | } |
321 | 305 |
|
322 | 306 | /** |
|
0 commit comments