Composer Workspace global packages

This commit is contained in:
Clemens Schwaighofer
2023-08-02 14:52:33 +09:00
parent c383a7b7b7
commit 1fc144e178
239 changed files with 5659 additions and 2712 deletions

View File

@@ -31,6 +31,8 @@ class Filesystem
* If the target file is newer, it is overwritten only when the
* $overwriteNewerFiles option is set to true.
*
* @return void
*
* @throws FileNotFoundException When originFile doesn't exist
* @throws IOException When copy fails
*/
@@ -82,6 +84,8 @@ class Filesystem
/**
* Creates a directory recursively.
*
* @return void
*
* @throws IOException On any directory creation failure
*/
public function mkdir(string|iterable $dirs, int $mode = 0777)
@@ -123,6 +127,8 @@ class Filesystem
* @param int|null $time The touch time as a Unix timestamp, if not supplied the current system time is used
* @param int|null $atime The access time as a Unix timestamp, if not supplied the current system time is used
*
* @return void
*
* @throws IOException When touch fails
*/
public function touch(string|iterable $files, int $time = null, int $atime = null)
@@ -137,6 +143,8 @@ class Filesystem
/**
* Removes files or directories.
*
* @return void
*
* @throws IOException When removal fails
*/
public function remove(string|iterable $files)
@@ -203,12 +211,14 @@ class Filesystem
* @param int $umask The mode mask (octal)
* @param bool $recursive Whether change the mod recursively or not
*
* @return void
*
* @throws IOException When the change fails
*/
public function chmod(string|iterable $files, int $mode, int $umask = 0000, bool $recursive = false)
{
foreach ($this->toIterable($files) as $file) {
if (\is_int($mode) && !self::box('chmod', $file, $mode & ~$umask)) {
if (!self::box('chmod', $file, $mode & ~$umask)) {
throw new IOException(sprintf('Failed to chmod file "%s": ', $file).self::$lastError, 0, null, $file);
}
if ($recursive && is_dir($file) && !is_link($file)) {
@@ -223,6 +233,8 @@ class Filesystem
* @param string|int $user A user name or number
* @param bool $recursive Whether change the owner recursively or not
*
* @return void
*
* @throws IOException When the change fails
*/
public function chown(string|iterable $files, string|int $user, bool $recursive = false)
@@ -249,6 +261,8 @@ class Filesystem
* @param string|int $group A group name or number
* @param bool $recursive Whether change the group recursively or not
*
* @return void
*
* @throws IOException When the change fails
*/
public function chgrp(string|iterable $files, string|int $group, bool $recursive = false)
@@ -272,6 +286,8 @@ class Filesystem
/**
* Renames a file or a directory.
*
* @return void
*
* @throws IOException When target file or directory already exists
* @throws IOException When origin cannot be renamed
*/
@@ -313,6 +329,8 @@ class Filesystem
/**
* Creates a symbolic link or copy a directory.
*
* @return void
*
* @throws IOException When symlink fails
*/
public function symlink(string $originDir, string $targetDir, bool $copyOnWindows = false)
@@ -349,6 +367,8 @@ class Filesystem
*
* @param string|string[] $targetFiles The target file(s)
*
* @return void
*
* @throws FileNotFoundException When original file is missing or not a file
* @throws IOException When link fails, including if link already exists
*/
@@ -381,7 +401,7 @@ class Filesystem
/**
* @param string $linkType Name of the link type, typically 'symbolic' or 'hard'
*/
private function linkException(string $origin, string $target, string $linkType)
private function linkException(string $origin, string $target, string $linkType): never
{
if (self::$lastError) {
if ('\\' === \DIRECTORY_SEPARATOR && str_contains(self::$lastError, 'error code(1314)')) {
@@ -438,11 +458,9 @@ class Filesystem
$startPath = str_replace('\\', '/', $startPath);
}
$splitDriveLetter = function ($path) {
return (\strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0]))
? [substr($path, 2), strtoupper($path[0])]
: [$path, null];
};
$splitDriveLetter = fn ($path) => (\strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0]))
? [substr($path, 2), strtoupper($path[0])]
: [$path, null];
$splitPath = function ($path) {
$result = [];
@@ -508,6 +526,8 @@ class Filesystem
* - $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink(), defaults to false)
* - $options['delete'] Whether to delete files that are not in the source directory (defaults to false)
*
* @return void
*
* @throws IOException When file type is unknown
*/
public function mirror(string $originDir, string $targetDir, \Traversable $iterator = null, array $options = [])
@@ -632,6 +652,8 @@ class Filesystem
*
* @param string|resource $content The data to write into the file
*
* @return void
*
* @throws IOException if the file cannot be written to
*/
public function dumpFile(string $filename, $content)
@@ -642,6 +664,12 @@ class Filesystem
$dir = \dirname($filename);
if (is_link($filename) && $linkTarget = $this->readlink($filename)) {
$this->dumpFile(Path::makeAbsolute($linkTarget, $dir), $content);
return;
}
if (!is_dir($dir)) {
$this->mkdir($dir);
}
@@ -671,6 +699,8 @@ class Filesystem
* @param string|resource $content The content to append
* @param bool $lock Whether the file should be locked when writing to it
*
* @return void
*
* @throws IOException If the file is not writable
*/
public function appendToFile(string $filename, $content/* , bool $lock = false */)
@@ -730,7 +760,7 @@ class Filesystem
/**
* @internal
*/
public static function handleError(int $type, string $msg)
public static function handleError(int $type, string $msg): void
{
self::$lastError = $msg;
}