Skip to content

Commit 84b79c6

Browse files
Prevent unresolvable APP_URL (#240)
* Prevent unresolvable `APP_URL` * formatting Co-authored-by: Taylor Otwell <[email protected]>
1 parent 60bfcb8 commit 84b79c6

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/NewCommand.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
108108
if ($name !== '.') {
109109
$this->replaceInFile(
110110
'APP_URL=http://localhost',
111-
'APP_URL=http://'.strtolower($name).'.test',
111+
'APP_URL='.$this->generateAppUrl($name),
112112
$directory.'/.env'
113113
);
114114

@@ -308,6 +308,30 @@ protected function verifyApplicationDoesntExist($directory)
308308
}
309309
}
310310

311+
/**
312+
* Generate a valid APP_URL for the given application name.
313+
*
314+
* @param string $name
315+
* @return string
316+
*/
317+
protected function generateAppUrl($name)
318+
{
319+
$hostname = mb_strtolower($name).'.test';
320+
321+
return $this->canResolveHostname($hostname) ? 'http://'.$hostname : 'http://localhost';
322+
}
323+
324+
/**
325+
* Determine whether the given hostname is resolvable.
326+
*
327+
* @param string $hostname
328+
* @return bool
329+
*/
330+
protected function canResolveHostname($hostname)
331+
{
332+
return gethostbyname($hostname.'.') !== $hostname.'.';
333+
}
334+
311335
/**
312336
* Get the version that should be downloaded.
313337
*

0 commit comments

Comments
 (0)