<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; class MockSplFileInfo extends \SplFileInfo { public const TYPE_DIRECTORY = 1; public const TYPE_FILE = 2; public const TYPE_UNKNOWN = 3; private $contents = null; private $mode = null; private $type = null; private $relativePath = null; private $relativePathname = null; public function __construct($param) { if (\is_string($param)) { parent::__construct($param); } elseif (\is_array($param)) { $defaults = [ 'name' => 'file.txt', 'contents' => null, 'mode' => null, 'type' => null, 'relativePath' => null, 'relativePathname' => null, ]; $defaults = array_merge($defaults, $param); parent::__construct($defaults['name']); $this->setContents($defaults['contents']); $this->setMode($defaults['mode']); $this->setType($defaults['type']); $this->setRelativePath($defaults['relativePath']); $this->setRelativePathname($defaults['relativePathname']); } else { throw new \RuntimeException(sprintf('Incorrect parameter "%s"', $param)); } } public function isFile(): bool { if (null === $this->type) { return str_contains($this->getFilename(), 'file'); } return self::TYPE_FILE === $this->type; } public function isDir(): bool { if (null === $this->type) { return str_contains($this->getFilename(), 'directory'); } return self::TYPE_DIRECTORY === $this->type; } public function isReadable(): bool { return (bool) preg_match('/r\+/', $this->mode ?? $this->getFilename()); } public function getContents() { return $this->contents; } public function setContents($contents) { $this->contents = $contents; } public function setMode($mode) { $this->mode = $mode; } public function setType($type) { if (\is_string($type)) { $this->type = match ($type) { 'directory', 'd' => self::TYPE_DIRECTORY, 'file', 'f' => self::TYPE_FILE, default => self::TYPE_UNKNOWN, }; } else { $this->type = $type; } } public function setRelativePath($relativePath) { $this->relativePath = $relativePath; } public function setRelativePathname($relativePathname) { $this->relativePathname = $relativePathname; } public function getRelativePath() { return $this->relativePath; } public function getRelativePathname() { return $this->relativePathname; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
CustomFilterIteratorTest.php | File | 1.22 KB | 0644 |
|
DateRangeFilterIteratorTest.php | File | 2.51 KB | 0644 |
|
DepthRangeFilterIteratorTest.php | File | 2.8 KB | 0644 |
|
ExcludeDirectoryFilterIteratorTest.php | File | 2.92 KB | 0644 |
|
FileTypeFilterIteratorTest.php | File | 1.99 KB | 0644 |
|
FilecontentFilterIteratorTest.php | File | 2.56 KB | 0644 |
|
FilenameFilterIteratorTest.php | File | 1.19 KB | 0644 |
|
InnerNameIterator.php | File | 555 B | 0644 |
|
Iterator.php | File | 1.1 KB | 0644 |
|
IteratorTestCase.php | File | 3.43 KB | 0644 |
|
LazyIteratorTest.php | File | 1.26 KB | 0644 |
|
MockFileListIterator.php | File | 568 B | 0644 |
|
MockSplFileInfo.php | File | 3.18 KB | 0644 |
|
MultiplePcreFilterIteratorTest.php | File | 2.42 KB | 0644 |
|
PathFilterIteratorTest.php | File | 3.03 KB | 0644 |
|
RealIteratorTestCase.php | File | 4.84 KB | 0644 |
|
RecursiveDirectoryIteratorTest.php | File | 1.63 KB | 0644 |
|
SizeRangeFilterIteratorTest.php | File | 1.63 KB | 0644 |
|
SortableIteratorTest.php | File | 8.23 KB | 0644 |
|
VcsIgnoredFilterIteratorTest.php | File | 8.79 KB | 0644 |
|