mirror of
https://github.com/laravel/valet.git
synced 2026-02-07 09:10:03 +01:00
Unlink renamed links
This commit is contained in:
@@ -22,6 +22,43 @@ function __construct(Configuration $config, CommandLine $cli, Filesystem $files)
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the site.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return string
|
||||
*/
|
||||
private function getRealSiteName($name)
|
||||
{
|
||||
if (! is_null($name)) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
if (is_string($link = $this->getLinkNameByCurrentDir())) {
|
||||
return $link;
|
||||
}
|
||||
|
||||
return basename(getcwd());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get link name based on the current directory.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
private function getLinkNameByCurrentDir()
|
||||
{
|
||||
$count = count($links = $this->links()->where('path', getcwd()));
|
||||
|
||||
if ($count == 1) {
|
||||
return $links->shift()['site'];
|
||||
}
|
||||
|
||||
if ($count > 1) {
|
||||
throw new DomainException("There are {$count} links related to the current directory, please specify the name: valet unlink <name>.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the real hostname for the given path, checking links.
|
||||
*
|
||||
@@ -106,7 +143,12 @@ function getLinks($path, $certs)
|
||||
$secured = $certs->has($site);
|
||||
$url = ($secured ? 'https': 'http').'://'.$site.'.'.$config['domain'];
|
||||
|
||||
return [$site, $secured ? ' X': '', $url, $path];
|
||||
return [
|
||||
'site' => $site,
|
||||
'secured' => $secured ? ' X': '',
|
||||
'url' => $url,
|
||||
'path' => $path,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
@@ -118,9 +160,13 @@ function getLinks($path, $certs)
|
||||
*/
|
||||
function unlink($name)
|
||||
{
|
||||
$name = $this->getRealSiteName($name);
|
||||
|
||||
if ($this->files->exists($path = $this->sitesPath().'/'.$name)) {
|
||||
$this->files->unlink($path);
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user