comparison vendor/symfony/finder/Tests/Iterator/MockSplFileInfo.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Finder\Tests\Iterator;
13
14 class MockSplFileInfo extends \SplFileInfo
15 {
16 const TYPE_DIRECTORY = 1;
17 const TYPE_FILE = 2;
18 const TYPE_UNKNOWN = 3;
19
20 private $contents = null;
21 private $mode = null;
22 private $type = null;
23 private $relativePath = null;
24 private $relativePathname = null;
25
26 public function __construct($param)
27 {
28 if (is_string($param)) {
29 parent::__construct($param);
30 } elseif (is_array($param)) {
31 $defaults = array(
32 'name' => 'file.txt',
33 'contents' => null,
34 'mode' => null,
35 'type' => null,
36 'relativePath' => null,
37 'relativePathname' => null,
38 );
39 $defaults = array_merge($defaults, $param);
40 parent::__construct($defaults['name']);
41 $this->setContents($defaults['contents']);
42 $this->setMode($defaults['mode']);
43 $this->setType($defaults['type']);
44 $this->setRelativePath($defaults['relativePath']);
45 $this->setRelativePathname($defaults['relativePathname']);
46 } else {
47 throw new \RuntimeException(sprintf('Incorrect parameter "%s"', $param));
48 }
49 }
50
51 public function isFile()
52 {
53 if (null === $this->type) {
54 return false !== strpos($this->getFilename(), 'file');
55 }
56
57 return self::TYPE_FILE === $this->type;
58 }
59
60 public function isDir()
61 {
62 if (null === $this->type) {
63 return false !== strpos($this->getFilename(), 'directory');
64 }
65
66 return self::TYPE_DIRECTORY === $this->type;
67 }
68
69 public function isReadable()
70 {
71 if (null === $this->mode) {
72 return preg_match('/r\+/', $this->getFilename());
73 }
74
75 return preg_match('/r\+/', $this->mode);
76 }
77
78 public function getContents()
79 {
80 return $this->contents;
81 }
82
83 public function setContents($contents)
84 {
85 $this->contents = $contents;
86 }
87
88 public function setMode($mode)
89 {
90 $this->mode = $mode;
91 }
92
93 public function setType($type)
94 {
95 if (is_string($type)) {
96 switch ($type) {
97 case 'directory':
98 case 'd':
99 $this->type = self::TYPE_DIRECTORY;
100 break;
101 case 'file':
102 case 'f':
103 $this->type = self::TYPE_FILE;
104 break;
105 default:
106 $this->type = self::TYPE_UNKNOWN;
107 }
108 } else {
109 $this->type = $type;
110 }
111 }
112
113 public function setRelativePath($relativePath)
114 {
115 $this->relativePath = $relativePath;
116 }
117
118 public function setRelativePathname($relativePathname)
119 {
120 $this->relativePathname = $relativePathname;
121 }
122
123 public function getRelativePath()
124 {
125 return $this->relativePath;
126 }
127
128 public function getRelativePathname()
129 {
130 return $this->relativePathname;
131 }
132 }