SplFileInfo.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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;
  11. /**
  12. * Extends \SplFileInfo to support relative paths
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class SplFileInfo extends \SplFileInfo
  17. {
  18. private $relativePath;
  19. private $relativePathname;
  20. /**
  21. * Constructor
  22. *
  23. * @param string $file The file name
  24. * @param string $relativePath The relative path
  25. * @param string $relativePathname The relative path name
  26. */
  27. public function __construct($file, $relativePath, $relativePathname)
  28. {
  29. parent::__construct($file);
  30. $this->relativePath = $relativePath;
  31. $this->relativePathname = $relativePathname;
  32. }
  33. /**
  34. * Returns the relative path
  35. *
  36. * @return string the relative path
  37. */
  38. public function getRelativePath()
  39. {
  40. return $this->relativePath;
  41. }
  42. /**
  43. * Returns the relative path name
  44. *
  45. * @return string the relative path name
  46. */
  47. public function getRelativePathname()
  48. {
  49. return $this->relativePathname;
  50. }
  51. /**
  52. * Returns the contents of the file
  53. *
  54. * @return string the contents of the file
  55. *
  56. * @throws \RuntimeException
  57. */
  58. public function getContents()
  59. {
  60. $level = error_reporting(0);
  61. $content = file_get_contents($this->getPathname());
  62. error_reporting($level);
  63. if (false === $content) {
  64. $error = error_get_last();
  65. throw new \RuntimeException($error['message']);
  66. }
  67. return $content;
  68. }
  69. }