/**
*
* @param string $affix
* @param bool $removeOld
* @return string
*/
protected function getSockFile($affix, $removeOld)
{
if (Utils::isWindows()) {
//we have no unix domain sockets support
return '127.0.0.1';
}
//since all commands set setcwd() we can make sure we are in the current application folder
if ('/' === substr($this->socketPath, 0, 1)) {
$run = $this->socketPath;
} else {
$run = getcwd() . '/' . $this->socketPath;
}
if ('/' !== substr($run, -1)) {
$run .= '/';
}
if (!is_dir($run) && !mkdir($run, 0777, true)) {
throw new \RuntimeException(sprintf('Could not create %s folder.', $run));
}
$sock = $run . $affix . '.sock';
if ($removeOld && file_exists($sock)) {
unlink($sock);
}
return 'unix://' . $sock;
}