/home/techb158/ileadtechnology.com/vendor/spatie/laravel-backup/src/Tasks/Backup
Edit: /home/techb158/ileadtechnology.com/vendor/spatie/laravel-backup/src/Tasks/Backup/FileSelection.php (4192B)
includeFilesAndDirectories = collect($includeFilesAndDirectories);
$this->excludeFilesAndDirectories = collect();
}
/**
* Do not included the given files and directories.
*
* @param array|string $excludeFilesAndDirectories
*
* @return \Spatie\Backup\Tasks\Backup\FileSelection
*/
public function excludeFilesFrom($excludeFilesAndDirectories): self
{
$this->excludeFilesAndDirectories = $this->excludeFilesAndDirectories->merge($this->sanitize($excludeFilesAndDirectories));
return $this;
}
public function shouldFollowLinks(bool $shouldFollowLinks): self
{
$this->shouldFollowLinks = $shouldFollowLinks;
return $this;
}
/**
* Set if it should ignore the unreadable directories.
*
* @param boolean $ignoreUnreadableDirs
*
* @return \Spatie\Backup\Tasks\Backup\FileSelection
*/
public function shouldIgnoreUnreadableDirs(bool $ignoreUnreadableDirs): self
{
$this->shouldIgnoreUnreadableDirs = $ignoreUnreadableDirs;
return $this;
}
/**
* @return \Generator|string[]
*/
public function selectedFiles()
{
if ($this->includeFilesAndDirectories->isEmpty()) {
return [];
}
$finder = (new Finder())
->ignoreDotFiles(false)
->ignoreVCS(false);
if ($this->shouldFollowLinks) {
$finder->followLinks();
}
if ($this->shouldIgnoreUnreadableDirs) {
$finder->ignoreUnreadableDirs();
}
foreach ($this->includedFiles() as $includedFile) {
yield $includedFile;
}
if (! count($this->includedDirectories())) {
return;
}
$finder->in($this->includedDirectories());
foreach ($finder->getIterator() as $file) {
if ($this->shouldExclude($file)) {
continue;
}
yield $file->getPathname();
}
}
protected function includedFiles(): array
{
return $this->includeFilesAndDirectories->filter(function ($path) {
return is_file($path);
})->toArray();
}
protected function includedDirectories(): array
{
return $this->includeFilesAndDirectories->reject(function ($path) {
return is_file($path);
})->toArray();
}
protected function shouldExclude(string $path): bool
{
foreach ($this->excludeFilesAndDirectories as $excludedPath) {
if (Str::startsWith(realpath($path), $excludedPath)) {
return true;
}
}
return false;
}
/**
* @param string|array $paths
*
* @return \Illuminate\Support\Collection
*/
protected function sanitize($paths): Collection
{
return collect($paths)
->reject(function ($path) {
return $path === '';
})
->flatMap(function ($path) {
return glob($path);
})
->map(function ($path) {
return realpath($path);
})
->reject(function ($path) {
return $path === false;
});
}
}