PageRenderTime 33ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/symfony/finder/Tests/Iterator/MockSplFileInfo.php

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