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