mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
N°6934 - Symfony 6.4 - upgrade Symfony bundles to 6.4 (#580)
* Update Symfony lib to version ~6.4.0 * Update code missing return type * Add an iTop general configuration entry to store application secret (Symfony mandatory parameter) * Use dependency injection in ExceptionListener & UserProvider classes
This commit is contained in:
@@ -18,23 +18,18 @@ use Symfony\Component\Finder\SplFileInfo;
|
||||
* Extends the \RecursiveDirectoryIterator to support relative paths.
|
||||
*
|
||||
* @author Victor Berchet <victor@suumit.com>
|
||||
*
|
||||
* @extends \RecursiveDirectoryIterator<string, SplFileInfo>
|
||||
*/
|
||||
class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $ignoreUnreadableDirs;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $rewindable;
|
||||
private bool $ignoreUnreadableDirs;
|
||||
private bool $ignoreFirstRewind = true;
|
||||
|
||||
// these 3 properties take part of the performance optimization to avoid redoing the same work in all iterations
|
||||
private $rootPath;
|
||||
private $subPath;
|
||||
private $directorySeparator = '/';
|
||||
private string $rootPath;
|
||||
private string $subPath;
|
||||
private string $directorySeparator = '/';
|
||||
|
||||
/**
|
||||
* @throws \RuntimeException
|
||||
@@ -55,17 +50,15 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
|
||||
/**
|
||||
* Return an instance of SplFileInfo with support for relative paths.
|
||||
*
|
||||
* @return SplFileInfo
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function current()
|
||||
public function current(): SplFileInfo
|
||||
{
|
||||
// the logic here avoids redoing the same work in all iterations
|
||||
|
||||
if (null === $subPathname = $this->subPath) {
|
||||
$subPathname = $this->subPath = $this->getSubPath();
|
||||
if (!isset($this->subPath)) {
|
||||
$this->subPath = $this->getSubPath();
|
||||
}
|
||||
$subPathname = $this->subPath;
|
||||
if ('' !== $subPathname) {
|
||||
$subPathname .= $this->directorySeparator;
|
||||
}
|
||||
@@ -78,13 +71,7 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
return new SplFileInfo($basePath.$subPathname, $this->subPath, $subPathname);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $allowLinks
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function hasChildren($allowLinks = false)
|
||||
public function hasChildren(bool $allowLinks = false): bool
|
||||
{
|
||||
$hasChildren = parent::hasChildren($allowLinks);
|
||||
|
||||
@@ -96,19 +83,16 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
parent::getChildren();
|
||||
|
||||
return true;
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
} catch (\UnexpectedValueException) {
|
||||
// If directory is unreadable and finder is set to ignore it, skip children
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \RecursiveDirectoryIterator
|
||||
*
|
||||
* @throws AccessDeniedException
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getChildren()
|
||||
public function getChildren(): \RecursiveDirectoryIterator
|
||||
{
|
||||
try {
|
||||
$children = parent::getChildren();
|
||||
@@ -118,7 +102,6 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
$children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs;
|
||||
|
||||
// performance optimization to avoid redoing the same work in all children
|
||||
$children->rewindable = &$this->rewindable;
|
||||
$children->rootPath = $this->rootPath;
|
||||
}
|
||||
|
||||
@@ -128,41 +111,23 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do nothing for non rewindable stream.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function rewind()
|
||||
public function next(): void
|
||||
{
|
||||
if (false === $this->isRewindable()) {
|
||||
$this->ignoreFirstRewind = false;
|
||||
|
||||
parent::next();
|
||||
}
|
||||
|
||||
public function rewind(): void
|
||||
{
|
||||
// some streams like FTP are not rewindable, ignore the first rewind after creation,
|
||||
// as newly created DirectoryIterator does not need to be rewound
|
||||
if ($this->ignoreFirstRewind) {
|
||||
$this->ignoreFirstRewind = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
parent::rewind();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the stream is rewindable.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isRewindable()
|
||||
{
|
||||
if (null !== $this->rewindable) {
|
||||
return $this->rewindable;
|
||||
}
|
||||
|
||||
if (false !== $stream = @opendir($this->getPath())) {
|
||||
$infos = stream_get_meta_data($stream);
|
||||
closedir($stream);
|
||||
|
||||
if ($infos['seekable']) {
|
||||
return $this->rewindable = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->rewindable = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user