TYPO3  7.6
MockSplFileInfo.php
Go to the documentation of this file.
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 
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  $this->type = self::TYPE_DIRECTORY;
99  case 'd':
100  $this->type = self::TYPE_DIRECTORY;
101  break;
102  case 'file':
103  $this->type = self::TYPE_FILE;
104  case 'f':
105  $this->type = self::TYPE_FILE;
106  break;
107  default:
108  $this->type = self::TYPE_UNKNOWN;
109  }
110  } else {
111  $this->type = $type;
112  }
113  }
114 
116  {
117  $this->relativePath = $relativePath;
118  }
119 
121  {
122  $this->relativePathname = $relativePathname;
123  }
124 
125  public function getRelativePath()
126  {
127  return $this->relativePath;
128  }
129 
130  public function getRelativePathname()
131  {
133  }
134 }