code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
public function offsetExists(mixed $key) : bool
{
return $this->hasArgument($key);
}
|
ArrayAccess has argument.
@param string $key Array key
|
offsetExists
|
php
|
deptrac/deptrac
|
vendor/symfony/event-dispatcher/GenericEvent.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/event-dispatcher/GenericEvent.php
|
MIT
|
public function getIterator() : \ArrayIterator
{
return new \ArrayIterator($this->arguments);
}
|
IteratorAggregate for iterating over the object like an array.
@return \ArrayIterator<string, mixed>
|
getIterator
|
php
|
deptrac/deptrac
|
vendor/symfony/event-dispatcher/GenericEvent.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/event-dispatcher/GenericEvent.php
|
MIT
|
public function __call(string $method, array $arguments) : mixed
{
return $this->dispatcher->{$method}(...$arguments);
}
|
Proxies all method calls to the original event dispatcher.
@param string $method The method name
@param array $arguments The method arguments
|
__call
|
php
|
deptrac/deptrac
|
vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php
|
MIT
|
public function stopPropagation() : void
{
$this->propagationStopped = \true;
}
|
Stops the propagation of the event to further event listeners.
If multiple event listeners are connected to the same event, no
further event listener will be triggered once any trigger calls
stopPropagation().
|
stopPropagation
|
php
|
deptrac/deptrac
|
vendor/symfony/event-dispatcher-contracts/Event.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/event-dispatcher-contracts/Event.php
|
MIT
|
public function copy(string $originFile, string $targetFile, bool $overwriteNewerFiles = \false)
{
$originIsLocal = \stream_is_local($originFile) || 0 === \stripos($originFile, 'file://');
if ($originIsLocal && !\is_file($originFile)) {
throw new FileNotFoundException(\sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
}
$this->mkdir(\dirname($targetFile));
$doCopy = \true;
if (!$overwriteNewerFiles && !\parse_url($originFile, \PHP_URL_HOST) && \is_file($targetFile)) {
$doCopy = \filemtime($originFile) > \filemtime($targetFile);
}
if ($doCopy) {
// https://bugs.php.net/64634
if (!($source = self::box('fopen', $originFile, 'r'))) {
throw new IOException(\sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading: ', $originFile, $targetFile) . self::$lastError, 0, null, $originFile);
}
// Stream context created to allow files overwrite when using FTP stream wrapper - disabled by default
if (!($target = self::box('fopen', $targetFile, 'w', \false, \stream_context_create(['ftp' => ['overwrite' => \true]])))) {
throw new IOException(\sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing: ', $originFile, $targetFile) . self::$lastError, 0, null, $originFile);
}
$bytesCopied = \stream_copy_to_stream($source, $target);
\fclose($source);
\fclose($target);
unset($source, $target);
if (!\is_file($targetFile)) {
throw new IOException(\sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
}
if ($originIsLocal) {
// Like `cp`, preserve executable permission bits
self::box('chmod', $targetFile, \fileperms($targetFile) | \fileperms($originFile) & 0111);
// Like `cp`, preserve the file modification time
self::box('touch', $targetFile, \filemtime($originFile));
if ($bytesCopied !== ($bytesOrigin = \filesize($originFile))) {
throw new IOException(\sprintf('Failed to copy the whole content of "%s" to "%s" (%g of %g bytes copied).', $originFile, $targetFile, $bytesCopied, $bytesOrigin), 0, null, $originFile);
}
}
}
}
|
Copies a file.
If the target file is older than the origin file, it's always overwritten.
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
|
copy
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function mkdir(string|iterable $dirs, int $mode = 0777)
{
foreach ($this->toIterable($dirs) as $dir) {
if (\is_dir($dir)) {
continue;
}
if (!self::box('mkdir', $dir, $mode, \true) && !\is_dir($dir)) {
throw new IOException(\sprintf('Failed to create "%s": ', $dir) . self::$lastError, 0, null, $dir);
}
}
}
|
Creates a directory recursively.
@return void
@throws IOException On any directory creation failure
|
mkdir
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function exists(string|iterable $files) : bool
{
$maxPathLength = \PHP_MAXPATHLEN - 2;
foreach ($this->toIterable($files) as $file) {
if (\strlen($file) > $maxPathLength) {
throw new IOException(\sprintf('Could not check if file exist because path length exceeds %d characters.', $maxPathLength), 0, null, $file);
}
if (!\file_exists($file)) {
return \false;
}
}
return \true;
}
|
Checks the existence of files or directories.
|
exists
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function touch(string|iterable $files, ?int $time = null, ?int $atime = null)
{
foreach ($this->toIterable($files) as $file) {
if (!($time ? self::box('touch', $file, $time, $atime) : self::box('touch', $file))) {
throw new IOException(\sprintf('Failed to touch "%s": ', $file) . self::$lastError, 0, null, $file);
}
}
}
|
Sets access and modification time of file.
@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
|
touch
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function remove(string|iterable $files)
{
if ($files instanceof \Traversable) {
$files = \iterator_to_array($files, \false);
} elseif (!\is_array($files)) {
$files = [$files];
}
self::doRemove($files, \false);
}
|
Removes files or directories.
@return void
@throws IOException When removal fails
|
remove
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function chmod(string|iterable $files, int $mode, int $umask = 00, bool $recursive = \false)
{
foreach ($this->toIterable($files) as $file) {
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)) {
$this->chmod(new \FilesystemIterator($file), $mode, $umask, \true);
}
}
}
|
Change mode for an array of files or directories.
@param int $mode The new mode (octal)
@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
|
chmod
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function chown(string|iterable $files, string|int $user, bool $recursive = \false)
{
foreach ($this->toIterable($files) as $file) {
if ($recursive && \is_dir($file) && !\is_link($file)) {
$this->chown(new \FilesystemIterator($file), $user, \true);
}
if (\is_link($file) && \function_exists('lchown')) {
if (!self::box('lchown', $file, $user)) {
throw new IOException(\sprintf('Failed to chown file "%s": ', $file) . self::$lastError, 0, null, $file);
}
} else {
if (!self::box('chown', $file, $user)) {
throw new IOException(\sprintf('Failed to chown file "%s": ', $file) . self::$lastError, 0, null, $file);
}
}
}
}
|
Change the owner of an array of files or directories.
This method always throws on Windows, as the underlying PHP function is not supported.
@see https://www.php.net/chown
@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
|
chown
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function chgrp(string|iterable $files, string|int $group, bool $recursive = \false)
{
foreach ($this->toIterable($files) as $file) {
if ($recursive && \is_dir($file) && !\is_link($file)) {
$this->chgrp(new \FilesystemIterator($file), $group, \true);
}
if (\is_link($file) && \function_exists('lchgrp')) {
if (!self::box('lchgrp', $file, $group)) {
throw new IOException(\sprintf('Failed to chgrp file "%s": ', $file) . self::$lastError, 0, null, $file);
}
} else {
if (!self::box('chgrp', $file, $group)) {
throw new IOException(\sprintf('Failed to chgrp file "%s": ', $file) . self::$lastError, 0, null, $file);
}
}
}
}
|
Change the group of an array of files or directories.
This method always throws on Windows, as the underlying PHP function is not supported.
@see https://www.php.net/chgrp
@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
|
chgrp
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function rename(string $origin, string $target, bool $overwrite = \false)
{
// we check that target does not exist
if (!$overwrite && $this->isReadable($target)) {
throw new IOException(\sprintf('Cannot rename because the target "%s" already exists.', $target), 0, null, $target);
}
if (!self::box('rename', $origin, $target)) {
if (\is_dir($origin)) {
// See https://bugs.php.net/54097 & https://php.net/rename#113943
$this->mirror($origin, $target, null, ['override' => $overwrite, 'delete' => $overwrite]);
$this->remove($origin);
return;
}
throw new IOException(\sprintf('Cannot rename "%s" to "%s": ', $origin, $target) . self::$lastError, 0, null, $target);
}
}
|
Renames a file or a directory.
@return void
@throws IOException When target file or directory already exists
@throws IOException When origin cannot be renamed
|
rename
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
private function isReadable(string $filename) : bool
{
$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);
}
return \is_readable($filename);
}
|
Tells whether a file exists and is readable.
@throws IOException When windows path is longer than 258 characters
|
isReadable
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function symlink(string $originDir, string $targetDir, bool $copyOnWindows = \false)
{
self::assertFunctionExists('symlink');
if ('\\' === \DIRECTORY_SEPARATOR) {
$originDir = \strtr($originDir, '/', '\\');
$targetDir = \strtr($targetDir, '/', '\\');
if ($copyOnWindows) {
$this->mirror($originDir, $targetDir);
return;
}
}
$this->mkdir(\dirname($targetDir));
if (\is_link($targetDir)) {
if (\readlink($targetDir) === $originDir) {
return;
}
$this->remove($targetDir);
}
if (!self::box('symlink', $originDir, $targetDir)) {
$this->linkException($originDir, $targetDir, 'symbolic');
}
}
|
Creates a symbolic link or copy a directory.
@return void
@throws IOException When symlink fails
|
symlink
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function hardlink(string $originFile, string|iterable $targetFiles)
{
self::assertFunctionExists('link');
if (!$this->exists($originFile)) {
throw new FileNotFoundException(null, 0, null, $originFile);
}
if (!\is_file($originFile)) {
throw new FileNotFoundException(\sprintf('Origin file "%s" is not a file.', $originFile));
}
foreach ($this->toIterable($targetFiles) as $targetFile) {
if (\is_file($targetFile)) {
if (\fileinode($originFile) === \fileinode($targetFile)) {
continue;
}
$this->remove($targetFile);
}
if (!self::box('link', $originFile, $targetFile)) {
$this->linkException($originFile, $targetFile, 'hard');
}
}
}
|
Creates a hard link, or several hard links to a file.
@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
|
hardlink
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
private function linkException(string $origin, string $target, string $linkType) : never
{
if (self::$lastError) {
if ('\\' === \DIRECTORY_SEPARATOR && \str_contains(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('Failed to create "%s" link from "%s" to "%s": ', $linkType, $origin, $target) . self::$lastError, 0, null, $target);
}
|
@param string $linkType Name of the link type, typically 'symbolic' or 'hard'
|
linkException
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function readlink(string $path, bool $canonicalize = \false) : ?string
{
if (!$canonicalize && !\is_link($path)) {
return null;
}
if ($canonicalize) {
if (!$this->exists($path)) {
return null;
}
return \realpath($path);
}
return \readlink($path);
}
|
Resolves links in paths.
With $canonicalize = false (default)
- if $path does not exist or is not a link, returns null
- if $path is a link, returns the next direct target of the link without considering the existence of the target
With $canonicalize = true
- if $path does not exist, returns null
- if $path exists, returns its absolute fully resolved final version
|
readlink
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function makePathRelative(string $endPath, string $startPath) : string
{
if (!$this->isAbsolutePath($startPath)) {
throw new InvalidArgumentException(\sprintf('The start path "%s" is not absolute.', $startPath));
}
if (!$this->isAbsolutePath($endPath)) {
throw new InvalidArgumentException(\sprintf('The end path "%s" is not absolute.', $endPath));
}
// Normalize separators on Windows
if ('\\' === \DIRECTORY_SEPARATOR) {
$endPath = \str_replace('\\', '/', $endPath);
$startPath = \str_replace('\\', '/', $startPath);
}
$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 = [];
foreach (\explode('/', \trim($path, '/')) as $segment) {
if ('..' === $segment) {
\array_pop($result);
} elseif ('.' !== $segment && '' !== $segment) {
$result[] = $segment;
}
}
return $result;
};
[$endPath, $endDriveLetter] = $splitDriveLetter($endPath);
[$startPath, $startDriveLetter] = $splitDriveLetter($startPath);
$startPathArr = $splitPath($startPath);
$endPathArr = $splitPath($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;
while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) {
++$index;
}
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
if (1 === \count($startPathArr) && '' === $startPathArr[0]) {
$depth = 0;
} else {
$depth = \count($startPathArr) - $index;
}
// Repeated "../" for each level need to reach the common path
$traverser = \str_repeat('../', $depth);
$endPathRemainder = \implode('/', \array_slice($endPathArr, $index));
// Construct $endPath from traversing to the common path, then to the remaining $endPath
$relativePath = $traverser . ('' !== $endPathRemainder ? $endPathRemainder . '/' : '');
return '' === $relativePath ? './' : $relativePath;
}
|
Given an existing path, convert it to a path relative to a given starting path.
|
makePathRelative
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function mirror(string $originDir, string $targetDir, ?\Traversable $iterator = null, array $options = [])
{
$targetDir = \rtrim($targetDir, '/\\');
$originDir = \rtrim($originDir, '/\\');
$originDirLen = \strlen($originDir);
if (!$this->exists($originDir)) {
throw new IOException(\sprintf('The origin directory specified "%s" was not found.', $originDir), 0, null, $originDir);
}
// Iterate in destination folder to remove obsolete entries
if ($this->exists($targetDir) && isset($options['delete']) && $options['delete']) {
$deleteIterator = $iterator;
if (null === $deleteIterator) {
$flags = \FilesystemIterator::SKIP_DOTS;
$deleteIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($targetDir, $flags), \RecursiveIteratorIterator::CHILD_FIRST);
}
$targetDirLen = \strlen($targetDir);
foreach ($deleteIterator as $file) {
$origin = $originDir . \substr($file->getPathname(), $targetDirLen);
if (!$this->exists($origin)) {
$this->remove($file);
}
}
}
$copyOnWindows = $options['copy_on_windows'] ?? \false;
if (null === $iterator) {
$flags = $copyOnWindows ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
}
$this->mkdir($targetDir);
$filesCreatedWhileMirroring = [];
foreach ($iterator as $file) {
if ($file->getPathname() === $targetDir || $file->getRealPath() === $targetDir || isset($filesCreatedWhileMirroring[$file->getRealPath()])) {
continue;
}
$target = $targetDir . \substr($file->getPathname(), $originDirLen);
$filesCreatedWhileMirroring[$target] = \true;
if (!$copyOnWindows && \is_link($file)) {
$this->symlink($file->getLinkTarget(), $target);
} elseif (\is_dir($file)) {
$this->mkdir($target);
} elseif (\is_file($file)) {
$this->copy($file, $target, $options['override'] ?? \false);
} else {
throw new IOException(\sprintf('Unable to guess "%s" file type.', $file), 0, null, $file);
}
}
}
|
Mirrors a directory to another.
Copies files and directories from the origin directory into the target directory. By default:
- existing files in the target directory will be overwritten, except if they are newer (see the `override` option)
- files in the target directory that do not exist in the source directory will not be deleted (see the `delete` option)
@param \Traversable|null $iterator Iterator that filters which files and directories to copy, if null a recursive iterator is created
@param array $options An array of boolean options
Valid options are:
- $options['override'] If true, target files newer than origin files are overwritten (see copy(), defaults to false)
- $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
|
mirror
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function isAbsolutePath(string $file) : bool
{
return '' !== $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));
}
|
Returns whether the file path is an absolute path.
|
isAbsolutePath
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function tempnam(string $dir, string $prefix, string $suffix = '') : string
{
[$scheme, $hierarchy] = $this->getSchemeAndHierarchy($dir);
// If no scheme or scheme is "file" or "gs" (Google Cloud) create temp file in local filesystem
if ((null === $scheme || 'file' === $scheme || 'gs' === $scheme) && '' === $suffix) {
// If tempnam failed or no scheme return the filename otherwise prepend the scheme
if ($tmpFile = self::box('tempnam', $hierarchy, $prefix)) {
if (null !== $scheme && 'gs' !== $scheme) {
return $scheme . '://' . $tmpFile;
}
return $tmpFile;
}
throw new IOException('A temporary file could not be created: ' . self::$lastError);
}
// Loop until we create a valid temp file or have reached 10 attempts
for ($i = 0; $i < 10; ++$i) {
// Create a unique filename
$tmpFile = $dir . '/' . $prefix . \uniqid(\mt_rand(), \true) . $suffix;
// Use fopen instead of file_exists as some streams do not support stat
// Use mode 'x+' to atomically check existence and create to avoid a TOCTOU vulnerability
if (!($handle = self::box('fopen', $tmpFile, 'x+'))) {
continue;
}
// Close the file if it was successfully opened
self::box('fclose', $handle);
return $tmpFile;
}
throw new IOException('A temporary file could not be created: ' . self::$lastError);
}
|
Creates a temporary file with support for custom stream wrappers.
@param string $prefix The prefix of the generated temporary filename
Note: Windows uses only the first three characters of prefix
@param string $suffix The suffix of the generated temporary filename
@return string The new temporary filename (with path), or throw an exception on failure
|
tempnam
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function dumpFile(string $filename, $content)
{
if (\is_array($content)) {
throw new \TypeError(\sprintf('Argument 2 passed to "%s()" must be string or resource, array given.', __METHOD__));
}
$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);
}
// Will create a temp file with 0600 access rights
// when the filesystem supports chmod.
$tmpFile = $this->tempnam($dir, \basename($filename));
try {
if (\false === self::box('file_put_contents', $tmpFile, $content)) {
throw new IOException(\sprintf('Failed to write file "%s": ', $filename) . self::$lastError, 0, null, $filename);
}
self::box('chmod', $tmpFile, self::box('fileperms', $filename) ?: 0666 & ~\umask());
$this->rename($tmpFile, $filename, \true);
} finally {
if (\file_exists($tmpFile)) {
if ('\\' === \DIRECTORY_SEPARATOR && !\is_writable($tmpFile)) {
self::box('chmod', $tmpFile, self::box('fileperms', $tmpFile) | 0200);
}
self::box('unlink', $tmpFile);
}
}
}
|
Atomically dumps content into a file.
@param string|resource $content The data to write into the file
@return void
@throws IOException if the file cannot be written to
|
dumpFile
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public function appendToFile(string $filename, $content)
{
if (\is_array($content)) {
throw new \TypeError(\sprintf('Argument 2 passed to "%s()" must be string or resource, array given.', __METHOD__));
}
$dir = \dirname($filename);
if (!\is_dir($dir)) {
$this->mkdir($dir);
}
$lock = \func_num_args() > 2 && \func_get_arg(2);
if (\false === self::box('file_put_contents', $filename, $content, \FILE_APPEND | ($lock ? \LOCK_EX : 0))) {
throw new IOException(\sprintf('Failed to write file "%s": ', $filename) . self::$lastError, 0, null, $filename);
}
}
|
Appends content to an existing file.
@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
|
appendToFile
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
private function getSchemeAndHierarchy(string $filename) : array
{
$components = \explode('://', $filename, 2);
return 2 === \count($components) ? [$components[0], $components[1]] : [null, $components[0]];
}
|
Gets a 2-tuple of scheme (may be null) and hierarchical part of a filename (e.g. file:///tmp -> [file, tmp]).
|
getSchemeAndHierarchy
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Filesystem.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Filesystem.php
|
MIT
|
public static function canonicalize(string $path) : string
{
if ('' === $path) {
return '';
}
// This method is called by many other methods in this class. Buffer
// the canonicalized paths to make up for the severe performance
// decrease.
if (isset(self::$buffer[$path])) {
return self::$buffer[$path];
}
// Replace "~" with user's home directory.
if ('~' === $path[0]) {
$path = self::getHomeDirectory() . \substr($path, 1);
}
$path = self::normalize($path);
[$root, $pathWithoutRoot] = self::split($path);
$canonicalParts = self::findCanonicalParts($root, $pathWithoutRoot);
// Add the root directory again
self::$buffer[$path] = $canonicalPath = $root . \implode('/', $canonicalParts);
++self::$bufferSize;
// Clean up regularly to prevent memory leaks
if (self::$bufferSize > self::CLEANUP_THRESHOLD) {
self::$buffer = \array_slice(self::$buffer, -self::CLEANUP_SIZE, null, \true);
self::$bufferSize = self::CLEANUP_SIZE;
}
return $canonicalPath;
}
|
Canonicalizes the given path.
During normalization, all slashes are replaced by forward slashes ("/").
Furthermore, all "." and ".." segments are removed as far as possible.
".." segments at the beginning of relative paths are not removed.
```php
echo Path::canonicalize("\symfony\puli\..\css\style.css");
// => /symfony/css/style.css
echo Path::canonicalize("../css/./style.css");
// => ../css/style.css
```
This method is able to deal with both UNIX and Windows paths.
|
canonicalize
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function normalize(string $path) : string
{
return \str_replace('\\', '/', $path);
}
|
Normalizes the given path.
During normalization, all slashes are replaced by forward slashes ("/").
Contrary to {@link canonicalize()}, this method does not remove invalid
or dot path segments. Consequently, it is much more efficient and should
be used whenever the given path is known to be a valid, absolute system
path.
This method is able to deal with both UNIX and Windows paths.
|
normalize
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function getDirectory(string $path) : string
{
if ('' === $path) {
return '';
}
$path = self::canonicalize($path);
// Maintain scheme
if (\false !== ($schemeSeparatorPosition = \strpos($path, '://'))) {
$scheme = \substr($path, 0, $schemeSeparatorPosition + 3);
$path = \substr($path, $schemeSeparatorPosition + 3);
} else {
$scheme = '';
}
if (\false === ($dirSeparatorPosition = \strrpos($path, '/'))) {
return '';
}
// Directory equals root directory "/"
if (0 === $dirSeparatorPosition) {
return $scheme . '/';
}
// Directory equals Windows root "C:/"
if (2 === $dirSeparatorPosition && \ctype_alpha($path[0]) && ':' === $path[1]) {
return $scheme . \substr($path, 0, 3);
}
return $scheme . \substr($path, 0, $dirSeparatorPosition);
}
|
Returns the directory part of the path.
This method is similar to PHP's dirname(), but handles various cases
where dirname() returns a weird result:
- dirname() does not accept backslashes on UNIX
- dirname("C:/symfony") returns "C:", not "C:/"
- dirname("C:/") returns ".", not "C:/"
- dirname("C:") returns ".", not "C:/"
- dirname("symfony") returns ".", not ""
- dirname() does not canonicalize the result
This method fixes these shortcomings and behaves like dirname()
otherwise.
The result is a canonical path.
@return string The canonical directory part. Returns the root directory
if the root directory is passed. Returns an empty string
if a relative path is passed that contains no slashes.
Returns an empty string if an empty string is passed.
|
getDirectory
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function getHomeDirectory() : string
{
// For UNIX support
if (\getenv('HOME')) {
return self::canonicalize(\getenv('HOME'));
}
// For >= Windows8 support
if (\getenv('HOMEDRIVE') && \getenv('HOMEPATH')) {
return self::canonicalize(\getenv('HOMEDRIVE') . \getenv('HOMEPATH'));
}
throw new RuntimeException("Cannot find the home directory path: Your environment or operating system isn't supported.");
}
|
Returns canonical path of the user's home directory.
Supported operating systems:
- UNIX
- Windows8 and upper
If your operating system or environment isn't supported, an exception is thrown.
The result is a canonical path.
@throws RuntimeException If your operating system or environment isn't supported
|
getHomeDirectory
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function getRoot(string $path) : string
{
if ('' === $path) {
return '';
}
// Maintain scheme
if (\false !== ($schemeSeparatorPosition = \strpos($path, '://'))) {
$scheme = \substr($path, 0, $schemeSeparatorPosition + 3);
$path = \substr($path, $schemeSeparatorPosition + 3);
} else {
$scheme = '';
}
$firstCharacter = $path[0];
// UNIX root "/" or "\" (Windows style)
if ('/' === $firstCharacter || '\\' === $firstCharacter) {
return $scheme . '/';
}
$length = \strlen($path);
// Windows root
if ($length > 1 && ':' === $path[1] && \ctype_alpha($firstCharacter)) {
// Special case: "C:"
if (2 === $length) {
return $scheme . $path . '/';
}
// Normal case: "C:/ or "C:\"
if ('/' === $path[2] || '\\' === $path[2]) {
return $scheme . $firstCharacter . $path[1] . '/';
}
}
return '';
}
|
Returns the root directory of a path.
The result is a canonical path.
@return string The canonical root directory. Returns an empty string if
the given path is relative or empty.
|
getRoot
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function getFilenameWithoutExtension(string $path, ?string $extension = null) : string
{
if ('' === $path) {
return '';
}
if (null !== $extension) {
// remove extension and trailing dot
return \rtrim(\basename($path, $extension), '.');
}
return \pathinfo($path, \PATHINFO_FILENAME);
}
|
Returns the file name without the extension from a file path.
@param string|null $extension if specified, only that extension is cut
off (may contain leading dot)
|
getFilenameWithoutExtension
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function getExtension(string $path, bool $forceLowerCase = \false) : string
{
if ('' === $path) {
return '';
}
$extension = \pathinfo($path, \PATHINFO_EXTENSION);
if ($forceLowerCase) {
$extension = self::toLower($extension);
}
return $extension;
}
|
Returns the extension from a file path (without leading dot).
@param bool $forceLowerCase forces the extension to be lower-case
|
getExtension
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function hasExtension(string $path, $extensions = null, bool $ignoreCase = \false) : bool
{
if ('' === $path) {
return \false;
}
$actualExtension = self::getExtension($path, $ignoreCase);
// Only check if path has any extension
if ([] === $extensions || null === $extensions) {
return '' !== $actualExtension;
}
if (\is_string($extensions)) {
$extensions = [$extensions];
}
foreach ($extensions as $key => $extension) {
if ($ignoreCase) {
$extension = self::toLower($extension);
}
// remove leading '.' in extensions array
$extensions[$key] = \ltrim($extension, '.');
}
return \in_array($actualExtension, $extensions, \true);
}
|
Returns whether the path has an (or the specified) extension.
@param string $path the path string
@param string|string[]|null $extensions if null or not provided, checks if
an extension exists, otherwise
checks for the specified extension
or array of extensions (with or
without leading dot)
@param bool $ignoreCase whether to ignore case-sensitivity
|
hasExtension
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function changeExtension(string $path, string $extension) : string
{
if ('' === $path) {
return '';
}
$actualExtension = self::getExtension($path);
$extension = \ltrim($extension, '.');
// No extension for paths
if ('/' === \substr($path, -1)) {
return $path;
}
// No actual extension in path
if (empty($actualExtension)) {
return $path . ('.' === \substr($path, -1) ? '' : '.') . $extension;
}
return \substr($path, 0, -\strlen($actualExtension)) . $extension;
}
|
Changes the extension of a path string.
@param string $path The path string with filename.ext to change.
@param string $extension new extension (with or without leading dot)
@return string the path string with new file extension
|
changeExtension
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function makeAbsolute(string $path, string $basePath) : string
{
if ('' === $basePath) {
throw new InvalidArgumentException(\sprintf('The base path must be a non-empty string. Got: "%s".', $basePath));
}
if (!self::isAbsolute($basePath)) {
throw new InvalidArgumentException(\sprintf('The base path "%s" is not an absolute path.', $basePath));
}
if (self::isAbsolute($path)) {
return self::canonicalize($path);
}
if (\false !== ($schemeSeparatorPosition = \strpos($basePath, '://'))) {
$scheme = \substr($basePath, 0, $schemeSeparatorPosition + 3);
$basePath = \substr($basePath, $schemeSeparatorPosition + 3);
} else {
$scheme = '';
}
return $scheme . self::canonicalize(\rtrim($basePath, '/\\') . '/' . $path);
}
|
Turns a relative path into an absolute path in canonical form.
Usually, the relative path is appended to the given base path. Dot
segments ("." and "..") are removed/collapsed and all slashes turned
into forward slashes.
```php
echo Path::makeAbsolute("../style.css", "/symfony/puli/css");
// => /symfony/puli/style.css
```
If an absolute path is passed, that path is returned unless its root
directory is different than the one of the base path. In that case, an
exception is thrown.
```php
Path::makeAbsolute("/style.css", "/symfony/puli/css");
// => /style.css
Path::makeAbsolute("C:/style.css", "C:/symfony/puli/css");
// => C:/style.css
Path::makeAbsolute("C:/style.css", "/symfony/puli/css");
// InvalidArgumentException
```
If the base path is not an absolute path, an exception is thrown.
The result is a canonical path.
@param string $basePath an absolute base path
@throws InvalidArgumentException if the base path is not absolute or if
the given path is an absolute path with
a different root than the base path
|
makeAbsolute
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function makeRelative(string $path, string $basePath) : string
{
$path = self::canonicalize($path);
$basePath = self::canonicalize($basePath);
[$root, $relativePath] = self::split($path);
[$baseRoot, $relativeBasePath] = self::split($basePath);
// If the base path is given as absolute path and the path is already
// relative, consider it to be relative to the given absolute path
// already
if ('' === $root && '' !== $baseRoot) {
// If base path is already in its root
if ('' === $relativeBasePath) {
$relativePath = \ltrim($relativePath, './\\');
}
return $relativePath;
}
// If the passed path is absolute, but the base path is not, we
// cannot generate a relative path
if ('' !== $root && '' === $baseRoot) {
throw new InvalidArgumentException(\sprintf('The absolute path "%s" cannot be made relative to the relative path "%s". You should provide an absolute base path instead.', $path, $basePath));
}
// Fail if the roots of the two paths are different
if ($baseRoot && $root !== $baseRoot) {
throw new InvalidArgumentException(\sprintf('The path "%s" cannot be made relative to "%s", because they have different roots ("%s" and "%s").', $path, $basePath, $root, $baseRoot));
}
if ('' === $relativeBasePath) {
return $relativePath;
}
// Build a "../../" prefix with as many "../" parts as necessary
$parts = \explode('/', $relativePath);
$baseParts = \explode('/', $relativeBasePath);
$dotDotPrefix = '';
// Once we found a non-matching part in the prefix, we need to add
// "../" parts for all remaining parts
$match = \true;
foreach ($baseParts as $index => $basePart) {
if ($match && isset($parts[$index]) && $basePart === $parts[$index]) {
unset($parts[$index]);
continue;
}
$match = \false;
$dotDotPrefix .= '../';
}
return \rtrim($dotDotPrefix . \implode('/', $parts), '/');
}
|
Turns a path into a relative path.
The relative path is created relative to the given base path:
```php
echo Path::makeRelative("/symfony/style.css", "/symfony/puli");
// => ../style.css
```
If a relative path is passed and the base path is absolute, the relative
path is returned unchanged:
```php
Path::makeRelative("style.css", "/symfony/puli/css");
// => style.css
```
If both paths are relative, the relative path is created with the
assumption that both paths are relative to the same directory:
```php
Path::makeRelative("style.css", "symfony/puli/css");
// => ../../../style.css
```
If both paths are absolute, their root directory must be the same,
otherwise an exception is thrown:
```php
Path::makeRelative("C:/symfony/style.css", "/symfony/puli");
// InvalidArgumentException
```
If the passed path is absolute, but the base path is not, an exception
is thrown as well:
```php
Path::makeRelative("/symfony/style.css", "symfony/puli");
// InvalidArgumentException
```
If the base path is not an absolute path, an exception is thrown.
The result is a canonical path.
@throws InvalidArgumentException if the base path is not absolute or if
the given path has a different root
than the base path
|
makeRelative
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function isLocal(string $path) : bool
{
return '' !== $path && !\str_contains($path, '://');
}
|
Returns whether the given path is on the local filesystem.
|
isLocal
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function getLongestCommonBasePath(string ...$paths) : ?string
{
[$bpRoot, $basePath] = self::split(self::canonicalize(\reset($paths)));
for (\next($paths); null !== \key($paths) && '' !== $basePath; \next($paths)) {
[$root, $path] = self::split(self::canonicalize(\current($paths)));
// If we deal with different roots (e.g. C:/ vs. D:/), it's time
// to quit
if ($root !== $bpRoot) {
return null;
}
// Make the base path shorter until it fits into path
while (\true) {
if ('.' === $basePath) {
// No more base paths
$basePath = '';
// next path
continue 2;
}
// Prevent false positives for common prefixes
// see isBasePath()
if (\str_starts_with($path . '/', $basePath . '/')) {
// next path
continue 2;
}
$basePath = \dirname($basePath);
}
}
return $bpRoot . $basePath;
}
|
Returns the longest common base path in canonical form of a set of paths or
`null` if the paths are on different Windows partitions.
Dot segments ("." and "..") are removed/collapsed and all slashes turned
into forward slashes.
```php
$basePath = Path::getLongestCommonBasePath(
'/symfony/css/style.css',
'/symfony/css/..'
);
// => /symfony
```
The root is returned if no common base path can be found:
```php
$basePath = Path::getLongestCommonBasePath(
'/symfony/css/style.css',
'/puli/css/..'
);
// => /
```
If the paths are located on different Windows partitions, `null` is
returned.
```php
$basePath = Path::getLongestCommonBasePath(
'C:/symfony/css/style.css',
'D:/symfony/css/..'
);
// => null
```
|
getLongestCommonBasePath
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function join(string ...$paths) : string
{
$finalPath = null;
$wasScheme = \false;
foreach ($paths as $path) {
if ('' === $path) {
continue;
}
if (null === $finalPath) {
// For first part we keep slashes, like '/top', 'C:\' or 'phar://'
$finalPath = $path;
$wasScheme = \str_contains($path, '://');
continue;
}
// Only add slash if previous part didn't end with '/' or '\'
if (!\in_array(\substr($finalPath, -1), ['/', '\\'])) {
$finalPath .= '/';
}
// If first part included a scheme like 'phar://' we allow \current part to start with '/', otherwise trim
$finalPath .= $wasScheme ? $path : \ltrim($path, '/');
$wasScheme = \false;
}
if (null === $finalPath) {
return '';
}
return self::canonicalize($finalPath);
}
|
Joins two or more path strings into a canonical path.
|
join
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public static function isBasePath(string $basePath, string $ofPath) : bool
{
$basePath = self::canonicalize($basePath);
$ofPath = self::canonicalize($ofPath);
// Append slashes to prevent false positives when two paths have
// a common prefix, for example /base/foo and /base/foobar.
// Don't append a slash for the root "/", because then that root
// won't be discovered as common prefix ("//" is not a prefix of
// "/foobar/").
return \str_starts_with($ofPath . '/', \rtrim($basePath, '/') . '/');
}
|
Returns whether a path is a base path of another path.
Dot segments ("." and "..") are removed/collapsed and all slashes turned
into forward slashes.
```php
Path::isBasePath('/symfony', '/symfony/css');
// => true
Path::isBasePath('/symfony', '/symfony');
// => true
Path::isBasePath('/symfony', '/symfony/..');
// => false
Path::isBasePath('/symfony', '/puli');
// => false
```
|
isBasePath
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
private static function split(string $path) : array
{
if ('' === $path) {
return ['', ''];
}
// Remember scheme as part of the root, if any
if (\false !== ($schemeSeparatorPosition = \strpos($path, '://'))) {
$root = \substr($path, 0, $schemeSeparatorPosition + 3);
$path = \substr($path, $schemeSeparatorPosition + 3);
} else {
$root = '';
}
$length = \strlen($path);
// Remove and remember root directory
if (\str_starts_with($path, '/')) {
$root .= '/';
$path = $length > 1 ? \substr($path, 1) : '';
} elseif ($length > 1 && \ctype_alpha($path[0]) && ':' === $path[1]) {
if (2 === $length) {
// Windows special case: "C:"
$root .= $path . '/';
$path = '';
} elseif ('/' === $path[2]) {
// Windows normal case: "C:/"..
$root .= \substr($path, 0, 3);
$path = $length > 3 ? \substr($path, 3) : '';
}
}
return [$root, $path];
}
|
Splits a canonical path into its root directory and the remainder.
If the path has no root directory, an empty root directory will be
returned.
If the root directory is a Windows style partition, the resulting root
will always contain a trailing slash.
list ($root, $path) = Path::split("C:/symfony")
// => ["C:/", "symfony"]
list ($root, $path) = Path::split("C:")
// => ["C:/", ""]
@return array{string, string} an array with the root directory and the remaining relative path
|
split
|
php
|
deptrac/deptrac
|
vendor/symfony/filesystem/Path.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/filesystem/Path.php
|
MIT
|
public function directories() : static
{
$this->mode = Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES;
return $this;
}
|
Restricts the matching to directories only.
@return $this
|
directories
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function files() : static
{
$this->mode = Iterator\FileTypeFilterIterator::ONLY_FILES;
return $this;
}
|
Restricts the matching to files only.
@return $this
|
files
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function depth(string|int|array $levels) : static
{
foreach ((array) $levels as $level) {
$this->depths[] = new Comparator\NumberComparator($level);
}
return $this;
}
|
Adds tests for the directory depth.
Usage:
$finder->depth('> 1') // the Finder will start matching at level 1.
$finder->depth('< 3') // the Finder will descend at most 3 levels of directories below the starting point.
$finder->depth(['>= 1', '< 3'])
@param string|int|string[]|int[] $levels The depth level expression or an array of depth levels
@return $this
@see DepthRangeFilterIterator
@see NumberComparator
|
depth
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function date(string|array $dates) : static
{
foreach ((array) $dates as $date) {
$this->dates[] = new Comparator\DateComparator($date);
}
return $this;
}
|
Adds tests for file dates (last modified).
The date must be something that strtotime() is able to parse:
$finder->date('since yesterday');
$finder->date('until 2 days ago');
$finder->date('> now - 2 hours');
$finder->date('>= 2005-10-15');
$finder->date(['>= 2005-10-15', '<= 2006-05-27']);
@param string|string[] $dates A date range string or an array of date ranges
@return $this
@see strtotime
@see DateRangeFilterIterator
@see DateComparator
|
date
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function notName(string|array $patterns) : static
{
$this->notNames = \array_merge($this->notNames, (array) $patterns);
return $this;
}
|
Adds rules that files must not match.
@param string|string[] $patterns A pattern (a regexp, a glob, or a string) or an array of patterns
@return $this
@see FilenameFilterIterator
|
notName
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function contains(string|array $patterns) : static
{
$this->contains = \array_merge($this->contains, (array) $patterns);
return $this;
}
|
Adds tests that file contents must match.
Strings or PCRE patterns can be used:
$finder->contains('Lorem ipsum')
$finder->contains('/Lorem ipsum/i')
$finder->contains(['dolor', '/ipsum/i'])
@param string|string[] $patterns A pattern (string or regexp) or an array of patterns
@return $this
@see FilecontentFilterIterator
|
contains
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function notContains(string|array $patterns) : static
{
$this->notContains = \array_merge($this->notContains, (array) $patterns);
return $this;
}
|
Adds tests that file contents must not match.
Strings or PCRE patterns can be used:
$finder->notContains('Lorem ipsum')
$finder->notContains('/Lorem ipsum/i')
$finder->notContains(['lorem', '/dolor/i'])
@param string|string[] $patterns A pattern (string or regexp) or an array of patterns
@return $this
@see FilecontentFilterIterator
|
notContains
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function size(string|int|array $sizes) : static
{
foreach ((array) $sizes as $size) {
$this->sizes[] = new Comparator\NumberComparator($size);
}
return $this;
}
|
Adds tests for file sizes.
$finder->size('> 10K');
$finder->size('<= 1Ki');
$finder->size(4);
$finder->size(['> 10K', '< 20K'])
@param string|int|string[]|int[] $sizes A size range string or an integer or an array of size ranges
@return $this
@see SizeRangeFilterIterator
@see NumberComparator
|
size
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function exclude(string|array $dirs) : static
{
$this->exclude = \array_merge($this->exclude, (array) $dirs);
return $this;
}
|
Excludes directories.
Directories passed as argument must be relative to the ones defined with the `in()` method. For example:
$finder->in(__DIR__)->exclude('ruby');
@param string|array $dirs A directory path or an array of directories
@return $this
@see ExcludeDirectoryFilterIterator
|
exclude
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function ignoreDotFiles(bool $ignoreDotFiles) : static
{
if ($ignoreDotFiles) {
$this->ignore |= static::IGNORE_DOT_FILES;
} else {
$this->ignore &= ~static::IGNORE_DOT_FILES;
}
return $this;
}
|
Excludes "hidden" directories and files (starting with a dot).
This option is enabled by default.
@return $this
@see ExcludeDirectoryFilterIterator
|
ignoreDotFiles
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function ignoreVCS(bool $ignoreVCS) : static
{
if ($ignoreVCS) {
$this->ignore |= static::IGNORE_VCS_FILES;
} else {
$this->ignore &= ~static::IGNORE_VCS_FILES;
}
return $this;
}
|
Forces the finder to ignore version control directories.
This option is enabled by default.
@return $this
@see ExcludeDirectoryFilterIterator
|
ignoreVCS
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function ignoreVCSIgnored(bool $ignoreVCSIgnored) : static
{
if ($ignoreVCSIgnored) {
$this->ignore |= static::IGNORE_VCS_IGNORED_FILES;
} else {
$this->ignore &= ~static::IGNORE_VCS_IGNORED_FILES;
}
return $this;
}
|
Forces Finder to obey .gitignore and ignore files based on rules listed there.
This option is disabled by default.
@return $this
|
ignoreVCSIgnored
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public static function addVCSPattern(string|array $pattern)
{
foreach ((array) $pattern as $p) {
self::$vcsPatterns[] = $p;
}
self::$vcsPatterns = \array_unique(self::$vcsPatterns);
}
|
Adds VCS patterns.
@see ignoreVCS()
@param string|string[] $pattern VCS patterns to ignore
@return void
|
addVCSPattern
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function sort(\Closure $closure) : static
{
$this->sort = $closure;
return $this;
}
|
Sorts files and directories by an anonymous function.
The anonymous function receives two \SplFileInfo instances to compare.
This can be slow as all the matching files and directories must be retrieved for comparison.
@return $this
@see SortableIterator
|
sort
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function sortByExtension() : static
{
$this->sort = Iterator\SortableIterator::SORT_BY_EXTENSION;
return $this;
}
|
Sorts files and directories by extension.
This can be slow as all the matching files and directories must be retrieved for comparison.
@return $this
@see SortableIterator
|
sortByExtension
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function sortByName(bool $useNaturalSort = \false) : static
{
$this->sort = $useNaturalSort ? Iterator\SortableIterator::SORT_BY_NAME_NATURAL : Iterator\SortableIterator::SORT_BY_NAME;
return $this;
}
|
Sorts files and directories by name.
This can be slow as all the matching files and directories must be retrieved for comparison.
@return $this
@see SortableIterator
|
sortByName
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function sortByCaseInsensitiveName(bool $useNaturalSort = \false) : static
{
$this->sort = $useNaturalSort ? Iterator\SortableIterator::SORT_BY_NAME_NATURAL_CASE_INSENSITIVE : Iterator\SortableIterator::SORT_BY_NAME_CASE_INSENSITIVE;
return $this;
}
|
Sorts files and directories by name case insensitive.
This can be slow as all the matching files and directories must be retrieved for comparison.
@return $this
@see SortableIterator
|
sortByCaseInsensitiveName
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function sortBySize() : static
{
$this->sort = Iterator\SortableIterator::SORT_BY_SIZE;
return $this;
}
|
Sorts files and directories by size.
This can be slow as all the matching files and directories must be retrieved for comparison.
@return $this
@see SortableIterator
|
sortBySize
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function sortByType() : static
{
$this->sort = Iterator\SortableIterator::SORT_BY_TYPE;
return $this;
}
|
Sorts files and directories by type (directories before files), then by name.
This can be slow as all the matching files and directories must be retrieved for comparison.
@return $this
@see SortableIterator
|
sortByType
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function sortByAccessedTime() : static
{
$this->sort = Iterator\SortableIterator::SORT_BY_ACCESSED_TIME;
return $this;
}
|
Sorts files and directories by the last accessed time.
This is the time that the file was last accessed, read or written to.
This can be slow as all the matching files and directories must be retrieved for comparison.
@return $this
@see SortableIterator
|
sortByAccessedTime
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function sortByChangedTime() : static
{
$this->sort = Iterator\SortableIterator::SORT_BY_CHANGED_TIME;
return $this;
}
|
Sorts files and directories by the last inode changed time.
This is the time that the inode information was last modified (permissions, owner, group or other metadata).
On Windows, since inode is not available, changed time is actually the file creation time.
This can be slow as all the matching files and directories must be retrieved for comparison.
@return $this
@see SortableIterator
|
sortByChangedTime
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function sortByModifiedTime() : static
{
$this->sort = Iterator\SortableIterator::SORT_BY_MODIFIED_TIME;
return $this;
}
|
Sorts files and directories by the last modified time.
This is the last time the actual contents of the file were last modified.
This can be slow as all the matching files and directories must be retrieved for comparison.
@return $this
@see SortableIterator
|
sortByModifiedTime
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function filter(\Closure $closure) : static
{
$prune = 1 < \func_num_args() ? \func_get_arg(1) : \false;
$this->filters[] = $closure;
if ($prune) {
$this->pruneFilters[] = $closure;
}
return $this;
}
|
Filters the iterator with an anonymous function.
The anonymous function receives a \SplFileInfo and must return false
to remove files.
@param \Closure(SplFileInfo): bool $closure
@param bool $prune Whether to skip traversing directories further
@return $this
@see CustomFilterIterator
|
filter
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function followLinks() : static
{
$this->followLinks = \true;
return $this;
}
|
Forces the following of symlinks.
@return $this
|
followLinks
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function ignoreUnreadableDirs(bool $ignore = \true) : static
{
$this->ignoreUnreadableDirs = $ignore;
return $this;
}
|
Tells finder to ignore unreadable directories.
By default, scanning unreadable directories content throws an AccessDeniedException.
@return $this
|
ignoreUnreadableDirs
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function in(string|array $dirs) : static
{
$resolvedDirs = [];
foreach ((array) $dirs as $dir) {
if (\is_dir($dir)) {
$resolvedDirs[] = [$this->normalizeDir($dir)];
} elseif ($glob = \glob($dir, (\defined('GLOB_BRACE') ? \GLOB_BRACE : 0) | \GLOB_ONLYDIR | \GLOB_NOSORT)) {
\sort($glob);
$resolvedDirs[] = \array_map($this->normalizeDir(...), $glob);
} else {
throw new DirectoryNotFoundException(\sprintf('The "%s" directory does not exist.', $dir));
}
}
$this->dirs = \array_merge($this->dirs, ...$resolvedDirs);
return $this;
}
|
Searches files and directories which match defined rules.
@param string|string[] $dirs A directory path or an array of directories
@return $this
@throws DirectoryNotFoundException if one of the directories does not exist
|
in
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function getIterator() : \Iterator
{
if (0 === \count($this->dirs) && 0 === \count($this->iterators)) {
throw new \LogicException('You must call one of in() or append() methods before iterating over a Finder.');
}
if (1 === \count($this->dirs) && 0 === \count($this->iterators)) {
$iterator = $this->searchInDirectory($this->dirs[0]);
if ($this->sort || $this->reverseSorting) {
$iterator = (new Iterator\SortableIterator($iterator, $this->sort, $this->reverseSorting))->getIterator();
}
return $iterator;
}
$iterator = new \AppendIterator();
foreach ($this->dirs as $dir) {
$iterator->append(new \IteratorIterator(new LazyIterator(fn() => $this->searchInDirectory($dir))));
}
foreach ($this->iterators as $it) {
$iterator->append($it);
}
if ($this->sort || $this->reverseSorting) {
$iterator = (new Iterator\SortableIterator($iterator, $this->sort, $this->reverseSorting))->getIterator();
}
return $iterator;
}
|
Returns an Iterator for the current Finder configuration.
This method implements the IteratorAggregate interface.
@return \Iterator<string, SplFileInfo>
@throws \LogicException if the in() method has not been called
|
getIterator
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function append(iterable $iterator) : static
{
if ($iterator instanceof \IteratorAggregate) {
$this->iterators[] = $iterator->getIterator();
} elseif ($iterator instanceof \Iterator) {
$this->iterators[] = $iterator;
} elseif (\is_iterable($iterator)) {
$it = new \ArrayIterator();
foreach ($iterator as $file) {
$file = $file instanceof \SplFileInfo ? $file : new \SplFileInfo($file);
$it[$file->getPathname()] = $file;
}
$this->iterators[] = $it;
} else {
throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
}
return $this;
}
|
Appends an existing set of files/directories to the finder.
The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
@return $this
@throws \InvalidArgumentException when the given argument is not iterable
|
append
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function hasResults() : bool
{
foreach ($this->getIterator() as $_) {
return \true;
}
return \false;
}
|
Check if any results were found.
|
hasResults
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public function count() : int
{
return \iterator_count($this->getIterator());
}
|
Counts all the results collected by the iterators.
|
count
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
private function normalizeDir(string $dir) : string
{
if ('/' === $dir) {
return $dir;
}
$dir = \rtrim($dir, '/' . \DIRECTORY_SEPARATOR);
if (\preg_match('#^(ssh2\\.)?s?ftp://#', $dir)) {
$dir .= '/';
}
return $dir;
}
|
Normalizes given directory names by removing trailing slashes.
Excluding: (s)ftp:// or ssh2.(s)ftp:// wrapper
|
normalizeDir
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Finder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Finder.php
|
MIT
|
public static function toRegex(string $gitignoreFileContent) : string
{
return self::buildRegex($gitignoreFileContent, \false);
}
|
Returns a regexp which is the equivalent of the gitignore pattern.
Format specification: https://git-scm.com/docs/gitignore#_pattern_format
|
toRegex
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Gitignore.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Gitignore.php
|
MIT
|
public static function toRegex(string $glob, bool $strictLeadingDot = \true, bool $strictWildcardSlash = \true, string $delimiter = '#') : string
{
$firstByte = \true;
$escaping = \false;
$inCurlies = 0;
$regex = '';
$sizeGlob = \strlen($glob);
for ($i = 0; $i < $sizeGlob; ++$i) {
$car = $glob[$i];
if ($firstByte && $strictLeadingDot && '.' !== $car) {
$regex .= '(?=[^\\.])';
}
$firstByte = '/' === $car;
if ($firstByte && $strictWildcardSlash && isset($glob[$i + 2]) && '**' === $glob[$i + 1] . $glob[$i + 2] && (!isset($glob[$i + 3]) || '/' === $glob[$i + 3])) {
$car = '[^/]++/';
if (!isset($glob[$i + 3])) {
$car .= '?';
}
if ($strictLeadingDot) {
$car = '(?=[^\\.])' . $car;
}
$car = '/(?:' . $car . ')*';
$i += 2 + isset($glob[$i + 3]);
if ('/' === $delimiter) {
$car = \str_replace('/', '\\/', $car);
}
}
if ($delimiter === $car || '.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) {
$regex .= "\\{$car}";
} elseif ('*' === $car) {
$regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
} elseif ('?' === $car) {
$regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.');
} elseif ('{' === $car) {
$regex .= $escaping ? '\\{' : '(';
if (!$escaping) {
++$inCurlies;
}
} elseif ('}' === $car && $inCurlies) {
$regex .= $escaping ? '}' : ')';
if (!$escaping) {
--$inCurlies;
}
} elseif (',' === $car && $inCurlies) {
$regex .= $escaping ? ',' : '|';
} elseif ('\\' === $car) {
if ($escaping) {
$regex .= '\\\\';
$escaping = \false;
} else {
$escaping = \true;
}
continue;
} else {
$regex .= $car;
}
$escaping = \false;
}
return $delimiter . '^' . $regex . '$' . $delimiter;
}
|
Returns a regexp which is the equivalent of the glob pattern.
|
toRegex
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Glob.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Glob.php
|
MIT
|
public function __construct(string $file, string $relativePath, string $relativePathname)
{
parent::__construct($file);
$this->relativePath = $relativePath;
$this->relativePathname = $relativePathname;
}
|
@param string $file The file name
@param string $relativePath The relative path
@param string $relativePathname The relative path name
|
__construct
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/SplFileInfo.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/SplFileInfo.php
|
MIT
|
public function getRelativePath() : string
{
return $this->relativePath;
}
|
Returns the relative path.
This path does not contain the file name.
|
getRelativePath
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/SplFileInfo.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/SplFileInfo.php
|
MIT
|
public function getRelativePathname() : string
{
return $this->relativePathname;
}
|
Returns the relative path name.
This path contains the file name.
|
getRelativePathname
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/SplFileInfo.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/SplFileInfo.php
|
MIT
|
public function getContents() : string
{
\set_error_handler(function ($type, $msg) use(&$error) {
$error = $msg;
});
try {
$content = \file_get_contents($this->getPathname());
} finally {
\restore_error_handler();
}
if (\false === $content) {
throw new \RuntimeException($error);
}
return $content;
}
|
Returns the contents of the file.
@throws \RuntimeException
|
getContents
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/SplFileInfo.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/SplFileInfo.php
|
MIT
|
public function __construct(string $test)
{
if (!\preg_match('#^\\s*(==|!=|[<>]=?|after|since|before|until)?\\s*(.+?)\\s*$#i', $test, $matches)) {
throw new \InvalidArgumentException(\sprintf('Don\'t understand "%s" as a date test.', $test));
}
try {
$date = new \DateTimeImmutable($matches[2]);
$target = $date->format('U');
} catch (\Exception) {
throw new \InvalidArgumentException(\sprintf('"%s" is not a valid date.', $matches[2]));
}
$operator = $matches[1] ?? '==';
if ('since' === $operator || 'after' === $operator) {
$operator = '>';
}
if ('until' === $operator || 'before' === $operator) {
$operator = '<';
}
parent::__construct($target, $operator);
}
|
@param string $test A comparison string
@throws \InvalidArgumentException If the test is not understood
|
__construct
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Comparator/DateComparator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Comparator/DateComparator.php
|
MIT
|
public function __construct(?string $test)
{
if (null === $test || !\preg_match('#^\\s*(==|!=|[<>]=?)?\\s*([0-9\\.]+)\\s*([kmg]i?)?\\s*$#i', $test, $matches)) {
throw new \InvalidArgumentException(\sprintf('Don\'t understand "%s" as a number test.', $test ?? 'null'));
}
$target = $matches[2];
if (!\is_numeric($target)) {
throw new \InvalidArgumentException(\sprintf('Invalid number "%s".', $target));
}
if (isset($matches[3])) {
// magnitude
switch (\strtolower($matches[3])) {
case 'k':
$target *= 1000;
break;
case 'ki':
$target *= 1024;
break;
case 'm':
$target *= 1000000;
break;
case 'mi':
$target *= 1024 * 1024;
break;
case 'g':
$target *= 1000000000;
break;
case 'gi':
$target *= 1024 * 1024 * 1024;
break;
}
}
parent::__construct($target, $matches[1] ?: '==');
}
|
@param string|null $test A comparison string or null
@throws \InvalidArgumentException If the test is not understood
|
__construct
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Comparator/NumberComparator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Comparator/NumberComparator.php
|
MIT
|
public function __construct(\Iterator $iterator, array $filters)
{
foreach ($filters as $filter) {
if (!\is_callable($filter)) {
throw new \InvalidArgumentException('Invalid PHP callback.');
}
}
$this->filters = $filters;
parent::__construct($iterator);
}
|
@param \Iterator<string, \SplFileInfo> $iterator The Iterator to filter
@param callable[] $filters An array of PHP callbacks
@throws \InvalidArgumentException
|
__construct
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/CustomFilterIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/CustomFilterIterator.php
|
MIT
|
public function __construct(\Iterator $iterator, array $comparators)
{
$this->comparators = $comparators;
parent::__construct($iterator);
}
|
@param \Iterator<string, \SplFileInfo> $iterator
@param DateComparator[] $comparators
|
__construct
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/DateRangeFilterIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/DateRangeFilterIterator.php
|
MIT
|
public function __construct(\RecursiveIteratorIterator $iterator, int $minDepth = 0, int $maxDepth = \PHP_INT_MAX)
{
$this->minDepth = $minDepth;
$iterator->setMaxDepth(\PHP_INT_MAX === $maxDepth ? -1 : $maxDepth);
parent::__construct($iterator);
}
|
@param \RecursiveIteratorIterator<\RecursiveIterator<TKey, TValue>> $iterator The Iterator to filter
@param int $minDepth The min depth
@param int $maxDepth The max depth
|
__construct
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/DepthRangeFilterIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/DepthRangeFilterIterator.php
|
MIT
|
public function __construct(\Iterator $iterator, array $directories)
{
$this->iterator = $iterator;
$this->isRecursive = $iterator instanceof \RecursiveIterator;
$patterns = [];
foreach ($directories as $directory) {
if (!\is_string($directory)) {
if (!\is_callable($directory)) {
throw new \InvalidArgumentException('Invalid PHP callback.');
}
$this->pruneFilters[] = $directory;
continue;
}
$directory = \rtrim($directory, '/');
if (!$this->isRecursive || \str_contains($directory, '/')) {
$patterns[] = \preg_quote($directory, '#');
} else {
$this->excludedDirs[$directory] = \true;
}
}
if ($patterns) {
$this->excludedPattern = '#(?:^|/)(?:' . \implode('|', $patterns) . ')(?:/|$)#';
}
parent::__construct($iterator);
}
|
@param \Iterator<string, SplFileInfo> $iterator The Iterator to filter
@param list<string|callable(SplFileInfo):bool> $directories An array of directories to exclude
|
__construct
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php
|
MIT
|
protected function toRegex(string $str) : string
{
return $this->isRegex($str) ? $str : '/' . \preg_quote($str, '/') . '/';
}
|
Converts string to regexp if necessary.
@param string $str Pattern: string or regexp
|
toRegex
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
|
MIT
|
protected function toRegex(string $str) : string
{
return $this->isRegex($str) ? $str : Glob::toRegex($str);
}
|
Converts glob to regexp.
PCRE patterns are left unchanged.
Glob strings are transformed with Glob::toRegex().
@param string $str Pattern: glob or regexp
|
toRegex
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/FilenameFilterIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/FilenameFilterIterator.php
|
MIT
|
public function __construct(\Iterator $iterator, int $mode)
{
$this->mode = $mode;
parent::__construct($iterator);
}
|
@param \Iterator<string, \SplFileInfo> $iterator The Iterator to filter
@param int $mode The mode (self::ONLY_FILES or self::ONLY_DIRECTORIES)
|
__construct
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/FileTypeFilterIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/FileTypeFilterIterator.php
|
MIT
|
public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
{
foreach ($matchPatterns as $pattern) {
$this->matchRegexps[] = $this->toRegex($pattern);
}
foreach ($noMatchPatterns as $pattern) {
$this->noMatchRegexps[] = $this->toRegex($pattern);
}
parent::__construct($iterator);
}
|
@param \Iterator<TKey, TValue> $iterator The Iterator to filter
@param string[] $matchPatterns An array of patterns that need to match
@param string[] $noMatchPatterns An array of patterns that need to not match
|
__construct
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/MultiplePcreFilterIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/MultiplePcreFilterIterator.php
|
MIT
|
protected function isAccepted(string $string) : bool
{
// should at least not match one rule to exclude
foreach ($this->noMatchRegexps as $regex) {
if (\preg_match($regex, $string)) {
return \false;
}
}
// should at least match one rule
if ($this->matchRegexps) {
foreach ($this->matchRegexps as $regex) {
if (\preg_match($regex, $string)) {
return \true;
}
}
return \false;
}
// If there is no match rules, the file is accepted
return \true;
}
|
Checks whether the string is accepted by the regex filters.
If there is no regexps defined in the class, this method will accept the string.
Such case can be handled by child classes before calling the method if they want to
apply a different behavior.
|
isAccepted
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/MultiplePcreFilterIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/MultiplePcreFilterIterator.php
|
MIT
|
protected function isRegex(string $str) : bool
{
$availableModifiers = 'imsxuADU';
if (\PHP_VERSION_ID >= 80200) {
$availableModifiers .= 'n';
}
if (\preg_match('/^(.{3,}?)[' . $availableModifiers . ']*$/', $str, $m)) {
$start = \substr($m[1], 0, 1);
$end = \substr($m[1], -1);
if ($start === $end) {
return !\preg_match('/[*?[:alnum:] \\\\]/', $start);
}
foreach ([['{', '}'], ['(', ')'], ['[', ']'], ['<', '>']] as $delimiters) {
if ($start === $delimiters[0] && $end === $delimiters[1]) {
return \true;
}
}
}
return \false;
}
|
Checks whether the string is a regex.
|
isRegex
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/MultiplePcreFilterIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/MultiplePcreFilterIterator.php
|
MIT
|
protected function toRegex(string $str) : string
{
return $this->isRegex($str) ? $str : '/' . \preg_quote($str, '/') . '/';
}
|
Converts strings to regexp.
PCRE patterns are left unchanged.
Default conversion:
'lorem/ipsum/dolor' ==> 'lorem\/ipsum\/dolor/'
Use only / as directory separator (on Windows also).
@param string $str Pattern: regexp or dirname
|
toRegex
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/PathFilterIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/PathFilterIterator.php
|
MIT
|
public function current() : SplFileInfo
{
// the logic here avoids redoing the same work in all iterations
if (!isset($this->subPath)) {
$this->subPath = $this->getSubPath();
}
$subPathname = $this->subPath;
if ('' !== $subPathname) {
$subPathname .= $this->directorySeparator;
}
$subPathname .= $this->getFilename();
$basePath = $this->rootPath;
if ('/' !== $basePath && !\str_ends_with($basePath, $this->directorySeparator) && !\str_ends_with($basePath, '/')) {
$basePath .= $this->directorySeparator;
}
return new SplFileInfo($basePath . $subPathname, $this->subPath, $subPathname);
}
|
Return an instance of SplFileInfo with support for relative paths.
|
current
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/RecursiveDirectoryIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/RecursiveDirectoryIterator.php
|
MIT
|
public function __construct(\Iterator $iterator, array $comparators)
{
$this->comparators = $comparators;
parent::__construct($iterator);
}
|
@param \Iterator<string, \SplFileInfo> $iterator
@param NumberComparator[] $comparators
|
__construct
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/SizeRangeFilterIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/SizeRangeFilterIterator.php
|
MIT
|
public function __construct(\Traversable $iterator, int|callable $sort, bool $reverseOrder = \false)
{
$this->iterator = $iterator;
$order = $reverseOrder ? -1 : 1;
if (self::SORT_BY_NAME === $sort) {
$this->sort = static fn(\SplFileInfo $a, \SplFileInfo $b) => $order * \strcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
} elseif (self::SORT_BY_NAME_NATURAL === $sort) {
$this->sort = static fn(\SplFileInfo $a, \SplFileInfo $b) => $order * \strnatcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
} elseif (self::SORT_BY_NAME_CASE_INSENSITIVE === $sort) {
$this->sort = static fn(\SplFileInfo $a, \SplFileInfo $b) => $order * \strcasecmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
} elseif (self::SORT_BY_NAME_NATURAL_CASE_INSENSITIVE === $sort) {
$this->sort = static fn(\SplFileInfo $a, \SplFileInfo $b) => $order * \strnatcasecmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
} elseif (self::SORT_BY_TYPE === $sort) {
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use($order) {
if ($a->isDir() && $b->isFile()) {
return -$order;
} elseif ($a->isFile() && $b->isDir()) {
return $order;
}
return $order * \strcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
};
} elseif (self::SORT_BY_ACCESSED_TIME === $sort) {
$this->sort = static fn(\SplFileInfo $a, \SplFileInfo $b) => $order * ($a->getATime() - $b->getATime());
} elseif (self::SORT_BY_CHANGED_TIME === $sort) {
$this->sort = static fn(\SplFileInfo $a, \SplFileInfo $b) => $order * ($a->getCTime() - $b->getCTime());
} elseif (self::SORT_BY_MODIFIED_TIME === $sort) {
$this->sort = static fn(\SplFileInfo $a, \SplFileInfo $b) => $order * ($a->getMTime() - $b->getMTime());
} elseif (self::SORT_BY_EXTENSION === $sort) {
$this->sort = static fn(\SplFileInfo $a, \SplFileInfo $b) => $order * \strnatcmp($a->getExtension(), $b->getExtension());
} elseif (self::SORT_BY_SIZE === $sort) {
$this->sort = static fn(\SplFileInfo $a, \SplFileInfo $b) => $order * ($a->getSize() - $b->getSize());
} elseif (self::SORT_BY_NONE === $sort) {
$this->sort = $order;
} elseif (\is_callable($sort)) {
$this->sort = $reverseOrder ? static fn(\SplFileInfo $a, \SplFileInfo $b) => -$sort($a, $b) : $sort(...);
} else {
throw new \InvalidArgumentException('The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.');
}
}
|
@param \Traversable<string, \SplFileInfo> $iterator
@param int|callable $sort The sort type (SORT_BY_NAME, SORT_BY_TYPE, or a PHP callback)
@throws \InvalidArgumentException
|
__construct
|
php
|
deptrac/deptrac
|
vendor/symfony/finder/Iterator/SortableIterator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/finder/Iterator/SortableIterator.php
|
MIT
|
public static function ctype_alnum($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
}
|
Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise.
@see https://php.net/ctype-alnum
@param mixed $text
@return bool
|
ctype_alnum
|
php
|
deptrac/deptrac
|
vendor/symfony/polyfill-ctype/Ctype.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/polyfill-ctype/Ctype.php
|
MIT
|
public static function ctype_alpha($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text);
}
|
Returns TRUE if every character in text is a letter, FALSE otherwise.
@see https://php.net/ctype-alpha
@param mixed $text
@return bool
|
ctype_alpha
|
php
|
deptrac/deptrac
|
vendor/symfony/polyfill-ctype/Ctype.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/polyfill-ctype/Ctype.php
|
MIT
|
public static function ctype_cntrl($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text);
}
|
Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise.
@see https://php.net/ctype-cntrl
@param mixed $text
@return bool
|
ctype_cntrl
|
php
|
deptrac/deptrac
|
vendor/symfony/polyfill-ctype/Ctype.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/polyfill-ctype/Ctype.php
|
MIT
|
public static function ctype_digit($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text);
}
|
Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise.
@see https://php.net/ctype-digit
@param mixed $text
@return bool
|
ctype_digit
|
php
|
deptrac/deptrac
|
vendor/symfony/polyfill-ctype/Ctype.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/polyfill-ctype/Ctype.php
|
MIT
|
public static function ctype_graph($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text);
}
|
Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise.
@see https://php.net/ctype-graph
@param mixed $text
@return bool
|
ctype_graph
|
php
|
deptrac/deptrac
|
vendor/symfony/polyfill-ctype/Ctype.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/polyfill-ctype/Ctype.php
|
MIT
|
public static function ctype_lower($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text);
}
|
Returns TRUE if every character in text is a lowercase letter.
@see https://php.net/ctype-lower
@param mixed $text
@return bool
|
ctype_lower
|
php
|
deptrac/deptrac
|
vendor/symfony/polyfill-ctype/Ctype.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/symfony/polyfill-ctype/Ctype.php
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.