Subiendo proyecto completo sin restricciones de git ignore
This commit is contained in:
115
vendor/phpunit/php-file-iterator/src/Facade.php
vendored
Normal file
115
vendor/phpunit/php-file-iterator/src/Facade.php
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of phpunit/php-file-iterator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\FileIterator;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
use function array_unique;
|
||||
use function count;
|
||||
use function dirname;
|
||||
use function explode;
|
||||
use function is_file;
|
||||
use function is_string;
|
||||
use function realpath;
|
||||
use function sort;
|
||||
|
||||
class Facade
|
||||
{
|
||||
/**
|
||||
* @param array|string $paths
|
||||
* @param array|string $suffixes
|
||||
* @param array|string $prefixes
|
||||
*/
|
||||
public function getFilesAsArray($paths, $suffixes = '', $prefixes = '', array $exclude = [], bool $commonPath = false): array
|
||||
{
|
||||
if (is_string($paths)) {
|
||||
$paths = [$paths];
|
||||
}
|
||||
|
||||
$iterator = (new Factory)->getFileIterator($paths, $suffixes, $prefixes, $exclude);
|
||||
|
||||
$files = [];
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
$file = $file->getRealPath();
|
||||
|
||||
if ($file) {
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (is_file($path)) {
|
||||
$files[] = realpath($path);
|
||||
}
|
||||
}
|
||||
|
||||
$files = array_unique($files);
|
||||
sort($files);
|
||||
|
||||
if ($commonPath) {
|
||||
return [
|
||||
'commonPath' => $this->getCommonPath($files),
|
||||
'files' => $files,
|
||||
];
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
protected function getCommonPath(array $files): string
|
||||
{
|
||||
$count = count($files);
|
||||
|
||||
if ($count === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($count === 1) {
|
||||
return dirname($files[0]) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
$_files = [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
$_files[] = $_fileParts = explode(DIRECTORY_SEPARATOR, $file);
|
||||
|
||||
if (empty($_fileParts[0])) {
|
||||
$_fileParts[0] = DIRECTORY_SEPARATOR;
|
||||
}
|
||||
}
|
||||
|
||||
$common = '';
|
||||
$done = false;
|
||||
$j = 0;
|
||||
$count--;
|
||||
|
||||
while (!$done) {
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if ($_files[$i][$j] != $_files[$i + 1][$j]) {
|
||||
$done = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$done) {
|
||||
$common .= $_files[0][$j];
|
||||
|
||||
if ($j > 0) {
|
||||
$common .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
}
|
||||
|
||||
$j++;
|
||||
}
|
||||
|
||||
return DIRECTORY_SEPARATOR . $common;
|
||||
}
|
||||
}
|
||||
91
vendor/phpunit/php-file-iterator/src/Factory.php
vendored
Normal file
91
vendor/phpunit/php-file-iterator/src/Factory.php
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of phpunit/php-file-iterator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\FileIterator;
|
||||
|
||||
use const GLOB_ONLYDIR;
|
||||
use function array_filter;
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function glob;
|
||||
use function is_dir;
|
||||
use function is_string;
|
||||
use function realpath;
|
||||
use AppendIterator;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
|
||||
class Factory
|
||||
{
|
||||
/**
|
||||
* @param array|string $paths
|
||||
* @param array|string $suffixes
|
||||
* @param array|string $prefixes
|
||||
*/
|
||||
public function getFileIterator($paths, $suffixes = '', $prefixes = '', array $exclude = []): AppendIterator
|
||||
{
|
||||
if (is_string($paths)) {
|
||||
$paths = [$paths];
|
||||
}
|
||||
|
||||
$paths = $this->getPathsAfterResolvingWildcards($paths);
|
||||
$exclude = $this->getPathsAfterResolvingWildcards($exclude);
|
||||
|
||||
if (is_string($prefixes)) {
|
||||
if ($prefixes !== '') {
|
||||
$prefixes = [$prefixes];
|
||||
} else {
|
||||
$prefixes = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (is_string($suffixes)) {
|
||||
if ($suffixes !== '') {
|
||||
$suffixes = [$suffixes];
|
||||
} else {
|
||||
$suffixes = [];
|
||||
}
|
||||
}
|
||||
|
||||
$iterator = new AppendIterator;
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (is_dir($path)) {
|
||||
$iterator->append(
|
||||
new Iterator(
|
||||
$path,
|
||||
new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::FOLLOW_SYMLINKS | RecursiveDirectoryIterator::SKIP_DOTS)
|
||||
),
|
||||
$suffixes,
|
||||
$prefixes,
|
||||
$exclude
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $iterator;
|
||||
}
|
||||
|
||||
protected function getPathsAfterResolvingWildcards(array $paths): array
|
||||
{
|
||||
$_paths = [[]];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if ($locals = glob($path, GLOB_ONLYDIR)) {
|
||||
$_paths[] = array_map('\realpath', $locals);
|
||||
} else {
|
||||
$_paths[] = [realpath($path)];
|
||||
}
|
||||
}
|
||||
|
||||
return array_filter(array_merge(...$_paths));
|
||||
}
|
||||
}
|
||||
119
vendor/phpunit/php-file-iterator/src/Iterator.php
vendored
Normal file
119
vendor/phpunit/php-file-iterator/src/Iterator.php
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of phpunit/php-file-iterator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\FileIterator;
|
||||
|
||||
use function array_filter;
|
||||
use function array_map;
|
||||
use function preg_match;
|
||||
use function realpath;
|
||||
use function str_replace;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
use FilterIterator;
|
||||
|
||||
class Iterator extends FilterIterator
|
||||
{
|
||||
public const PREFIX = 0;
|
||||
|
||||
public const SUFFIX = 1;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $basePath;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $suffixes = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $prefixes = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $exclude = [];
|
||||
|
||||
public function __construct(string $basePath, \Iterator $iterator, array $suffixes = [], array $prefixes = [], array $exclude = [])
|
||||
{
|
||||
$this->basePath = realpath($basePath);
|
||||
$this->prefixes = $prefixes;
|
||||
$this->suffixes = $suffixes;
|
||||
$this->exclude = array_filter(array_map('realpath', $exclude));
|
||||
|
||||
parent::__construct($iterator);
|
||||
}
|
||||
|
||||
public function accept(): bool
|
||||
{
|
||||
$current = $this->getInnerIterator()->current();
|
||||
$filename = $current->getFilename();
|
||||
$realPath = $current->getRealPath();
|
||||
|
||||
if ($realPath === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->acceptPath($realPath) &&
|
||||
$this->acceptPrefix($filename) &&
|
||||
$this->acceptSuffix($filename);
|
||||
}
|
||||
|
||||
private function acceptPath(string $path): bool
|
||||
{
|
||||
// Filter files in hidden directories by checking path that is relative to the base path.
|
||||
if (preg_match('=/\.[^/]*/=', str_replace($this->basePath, '', $path))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->exclude as $exclude) {
|
||||
if (strpos($path, $exclude) === 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function acceptPrefix(string $filename): bool
|
||||
{
|
||||
return $this->acceptSubString($filename, $this->prefixes, self::PREFIX);
|
||||
}
|
||||
|
||||
private function acceptSuffix(string $filename): bool
|
||||
{
|
||||
return $this->acceptSubString($filename, $this->suffixes, self::SUFFIX);
|
||||
}
|
||||
|
||||
private function acceptSubString(string $filename, array $subStrings, int $type): bool
|
||||
{
|
||||
if (empty($subStrings)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$matched = false;
|
||||
|
||||
foreach ($subStrings as $string) {
|
||||
if (($type === self::PREFIX && strpos($filename, $string) === 0) ||
|
||||
($type === self::SUFFIX &&
|
||||
substr($filename, -1 * strlen($string)) === $string)) {
|
||||
$matched = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $matched;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user