public static function bold($message) { if (!OS::isWindows()) { echo "[1m"; } echo $message; if (!OS::isWindows()) { echo "[m"; } }
/** * deleteContents of a folder recursively, but not the folder itself. * * On Windows systems this will try to remove the read-only attribute if needed. * * @param string $path Path of folder whose contents will be deleted * * @throws \RuntimeException Thrown when something could not be deleted. */ public static function deleteContents($path) { if (!is_dir($path)) { return; } /** @var \SplFileInfo[] $files */ $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($files as $fileInfo) { if ($fileInfo->isDir()) { if (@rmdir($fileInfo->getRealPath()) === false) { throw new \RuntimeException(sprintf("Unable to delete child folder '%s' in '%s': %s", $fileInfo->getFilename(), $fileInfo->getPathname(), error_get_last()['message'])); } } elseif (@unlink($fileInfo->getRealPath()) === false) { if (OS::isWindows()) { Exec::create('attrib', '-R', $fileInfo->getRealPath())->run(); if (@unlink($fileInfo->getPathname())) { continue; } } throw new \RuntimeException(sprintf("Unable to delete file '%s' in folder '%s': %s", $fileInfo->getFilename(), $fileInfo->getPathname(), error_get_last()['message'])); } } }
/** * @param string $argument * * @return string */ private function escapeArgument($argument) { // Always escape an empty argument so it doesn't get lost. if ($argument === '') { return escapeshellarg($argument); } if (!OS::isWindows()) { return $this->escapeLinuxArgument($argument); } return $this->escapeWindowsArgument($argument); }