4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Finder;
15 * Extends \SplFileInfo to support relative paths.
17 * @author Fabien Potencier <fabien@symfony.com>
19 class SplFileInfo extends \SplFileInfo
21 private $relativePath;
22 private $relativePathname;
27 * @param string $file The file name
28 * @param string $relativePath The relative path
29 * @param string $relativePathname The relative path name
31 public function __construct($file, $relativePath, $relativePathname)
33 parent::__construct($file);
34 $this->relativePath = $relativePath;
35 $this->relativePathname = $relativePathname;
39 * Returns the relative path.
41 * This path does not contain the file name.
43 * @return string the relative path
45 public function getRelativePath()
47 return $this->relativePath;
51 * Returns the relative path name.
53 * This path contains the file name.
55 * @return string the relative path name
57 public function getRelativePathname()
59 return $this->relativePathname;
63 * Returns the contents of the file.
65 * @return string the contents of the file
67 * @throws \RuntimeException
69 public function getContents()
71 $level = error_reporting(0);
72 $content = file_get_contents($this->getPathname());
73 error_reporting($level);
74 if (false === $content) {
75 $error = error_get_last();
76 throw new \RuntimeException($error['message']);