mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-03 07:28:57 +02:00
⬆️ N°4770 Update to latest Symfony 3.4
This commit is contained in:
@@ -47,7 +47,7 @@ class Filesystem
|
||||
$this->mkdir(\dirname($targetFile));
|
||||
|
||||
$doCopy = true;
|
||||
if (!$overwriteNewerFiles && null === parse_url($originFile, PHP_URL_HOST) && is_file($targetFile)) {
|
||||
if (!$overwriteNewerFiles && null === parse_url($originFile, \PHP_URL_HOST) && is_file($targetFile)) {
|
||||
$doCopy = filemtime($originFile) > filemtime($targetFile);
|
||||
}
|
||||
|
||||
@@ -101,9 +101,9 @@ class Filesystem
|
||||
if (!is_dir($dir)) {
|
||||
// The directory was not created by a concurrent process. Let's throw an exception with a developer friendly error message if we have one
|
||||
if (self::$lastError) {
|
||||
throw new IOException(sprintf('Failed to create "%s": %s.', $dir, self::$lastError), 0, null, $dir);
|
||||
throw new IOException(sprintf('Failed to create "%s": ', $dir).self::$lastError, 0, null, $dir);
|
||||
}
|
||||
throw new IOException(sprintf('Failed to create "%s"', $dir), 0, null, $dir);
|
||||
throw new IOException(sprintf('Failed to create "%s".', $dir), 0, null, $dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ class Filesystem
|
||||
*/
|
||||
public function exists($files)
|
||||
{
|
||||
$maxPathLength = PHP_MAXPATHLEN - 2;
|
||||
$maxPathLength = \PHP_MAXPATHLEN - 2;
|
||||
|
||||
foreach ($this->toIterable($files) as $file) {
|
||||
if (\strlen($file) > $maxPathLength) {
|
||||
@@ -171,16 +171,16 @@ class Filesystem
|
||||
if (is_link($file)) {
|
||||
// See https://bugs.php.net/52176
|
||||
if (!(self::box('unlink', $file) || '\\' !== \DIRECTORY_SEPARATOR || self::box('rmdir', $file)) && file_exists($file)) {
|
||||
throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, self::$lastError));
|
||||
throw new IOException(sprintf('Failed to remove symlink "%s": ', $file).self::$lastError);
|
||||
}
|
||||
} elseif (is_dir($file)) {
|
||||
$this->remove(new \FilesystemIterator($file, \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS));
|
||||
|
||||
if (!self::box('rmdir', $file) && file_exists($file)) {
|
||||
throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, self::$lastError));
|
||||
throw new IOException(sprintf('Failed to remove directory "%s": ', $file).self::$lastError);
|
||||
}
|
||||
} elseif (!self::box('unlink', $file) && file_exists($file)) {
|
||||
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, self::$lastError));
|
||||
} elseif (!self::box('unlink', $file) && (false !== strpos(self::$lastError, 'Permission denied') || file_exists($file))) {
|
||||
throw new IOException(sprintf('Failed to remove file "%s": ', $file).self::$lastError);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ class Filesystem
|
||||
public function chmod($files, $mode, $umask = 0000, $recursive = false)
|
||||
{
|
||||
foreach ($this->toIterable($files) as $file) {
|
||||
if (true !== @chmod($file, $mode & ~$umask)) {
|
||||
if ((\PHP_VERSION_ID < 80000 || \is_int($mode)) && true !== @chmod($file, $mode & ~$umask)) {
|
||||
throw new IOException(sprintf('Failed to chmod file "%s".', $file), 0, null, $file);
|
||||
}
|
||||
if ($recursive && is_dir($file) && !is_link($file)) {
|
||||
@@ -211,7 +211,7 @@ class Filesystem
|
||||
* Change the owner of an array of files or directories.
|
||||
*
|
||||
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to change owner
|
||||
* @param string $user The new owner user name
|
||||
* @param string|int $user A user name or number
|
||||
* @param bool $recursive Whether change the owner recursively or not
|
||||
*
|
||||
* @throws IOException When the change fails
|
||||
@@ -238,7 +238,7 @@ class Filesystem
|
||||
* Change the group of an array of files or directories.
|
||||
*
|
||||
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to change group
|
||||
* @param string $group The group name
|
||||
* @param string|int $group A group name or number
|
||||
* @param bool $recursive Whether change the group recursively or not
|
||||
*
|
||||
* @throws IOException When the change fails
|
||||
@@ -301,7 +301,7 @@ class Filesystem
|
||||
*/
|
||||
private function isReadable($filename)
|
||||
{
|
||||
$maxPathLength = PHP_MAXPATHLEN - 2;
|
||||
$maxPathLength = \PHP_MAXPATHLEN - 2;
|
||||
|
||||
if (\strlen($filename) > $maxPathLength) {
|
||||
throw new IOException(sprintf('Could not check if file is readable because path length exceeds %d characters.', $maxPathLength), 0, null, $filename);
|
||||
@@ -362,7 +362,7 @@ class Filesystem
|
||||
}
|
||||
|
||||
if (!is_file($originFile)) {
|
||||
throw new FileNotFoundException(sprintf('Origin file "%s" is not a file', $originFile));
|
||||
throw new FileNotFoundException(sprintf('Origin file "%s" is not a file.', $originFile));
|
||||
}
|
||||
|
||||
foreach ($this->toIterable($targetFiles) as $targetFile) {
|
||||
@@ -388,10 +388,10 @@ class Filesystem
|
||||
{
|
||||
if (self::$lastError) {
|
||||
if ('\\' === \DIRECTORY_SEPARATOR && false !== strpos(self::$lastError, 'error code(1314)')) {
|
||||
throw new IOException(sprintf('Unable to create %s link due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?', $linkType), 0, null, $target);
|
||||
throw new IOException(sprintf('Unable to create "%s" link due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?', $linkType), 0, null, $target);
|
||||
}
|
||||
}
|
||||
throw new IOException(sprintf('Failed to create %s link from "%s" to "%s".', $linkType, $origin, $target), 0, null, $target);
|
||||
throw new IOException(sprintf('Failed to create "%s" link from "%s" to "%s".', $linkType, $origin, $target), 0, null, $target);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -446,7 +446,7 @@ class Filesystem
|
||||
public function makePathRelative($endPath, $startPath)
|
||||
{
|
||||
if (!$this->isAbsolutePath($endPath) || !$this->isAbsolutePath($startPath)) {
|
||||
@trigger_error(sprintf('Support for passing relative paths to %s() is deprecated since Symfony 3.4 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
@trigger_error(sprintf('Support for passing relative paths to %s() is deprecated since Symfony 3.4 and will be removed in 4.0.', __METHOD__), \E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
// Normalize separators on Windows
|
||||
@@ -455,28 +455,19 @@ class Filesystem
|
||||
$startPath = str_replace('\\', '/', $startPath);
|
||||
}
|
||||
|
||||
$stripDriveLetter = function ($path) {
|
||||
if (\strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0])) {
|
||||
return substr($path, 2);
|
||||
}
|
||||
|
||||
return $path;
|
||||
$splitDriveLetter = function ($path) {
|
||||
return (\strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0]))
|
||||
? [substr($path, 2), strtoupper($path[0])]
|
||||
: [$path, null];
|
||||
};
|
||||
|
||||
$endPath = $stripDriveLetter($endPath);
|
||||
$startPath = $stripDriveLetter($startPath);
|
||||
|
||||
// Split the paths into arrays
|
||||
$startPathArr = explode('/', trim($startPath, '/'));
|
||||
$endPathArr = explode('/', trim($endPath, '/'));
|
||||
|
||||
$normalizePathArray = function ($pathSegments, $absolute) {
|
||||
$splitPath = function ($path, $absolute) {
|
||||
$result = [];
|
||||
|
||||
foreach ($pathSegments as $segment) {
|
||||
foreach (explode('/', trim($path, '/')) as $segment) {
|
||||
if ('..' === $segment && ($absolute || \count($result))) {
|
||||
array_pop($result);
|
||||
} elseif ('.' !== $segment) {
|
||||
} elseif ('.' !== $segment && '' !== $segment) {
|
||||
$result[] = $segment;
|
||||
}
|
||||
}
|
||||
@@ -484,8 +475,16 @@ class Filesystem
|
||||
return $result;
|
||||
};
|
||||
|
||||
$startPathArr = $normalizePathArray($startPathArr, static::isAbsolutePath($startPath));
|
||||
$endPathArr = $normalizePathArray($endPathArr, static::isAbsolutePath($endPath));
|
||||
list($endPath, $endDriveLetter) = $splitDriveLetter($endPath);
|
||||
list($startPath, $startDriveLetter) = $splitDriveLetter($startPath);
|
||||
|
||||
$startPathArr = $splitPath($startPath, static::isAbsolutePath($startPath));
|
||||
$endPathArr = $splitPath($endPath, static::isAbsolutePath($endPath));
|
||||
|
||||
if ($endDriveLetter && $startDriveLetter && $endDriveLetter != $startDriveLetter) {
|
||||
// End path is on another drive, so no relative path exists
|
||||
return $endDriveLetter.':/'.($endPathArr ? implode('/', $endPathArr).'/' : '');
|
||||
}
|
||||
|
||||
// Find for which directory the common path stops
|
||||
$index = 0;
|
||||
@@ -600,13 +599,13 @@ class Filesystem
|
||||
*/
|
||||
public function isAbsolutePath($file)
|
||||
{
|
||||
return strspn($file, '/\\', 0, 1)
|
||||
return '' !== (string) $file && (strspn($file, '/\\', 0, 1)
|
||||
|| (\strlen($file) > 3 && ctype_alpha($file[0])
|
||||
&& ':' === $file[1]
|
||||
&& strspn($file, '/\\', 2, 1)
|
||||
)
|
||||
|| null !== parse_url($file, PHP_URL_SCHEME)
|
||||
;
|
||||
|| null !== parse_url($file, \PHP_URL_SCHEME)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -714,7 +713,7 @@ class Filesystem
|
||||
throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
|
||||
}
|
||||
|
||||
if (false === @file_put_contents($filename, $content, FILE_APPEND)) {
|
||||
if (false === @file_put_contents($filename, $content, \FILE_APPEND)) {
|
||||
throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user