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;
25 * @param string $file The file name
26 * @param string $relativePath The relative path
27 * @param string $relativePathname The relative path name
29 public function __construct($file, $relativePath, $relativePathname)
31 parent::__construct($file);
32 $this->relativePath = $relativePath;
33 $this->relativePathname = $relativePathname;
37 * Returns the relative path.
39 * This path does not contain the file name.
41 * @return string the relative path
43 public function getRelativePath()
45 return $this->relativePath;
49 * Returns the relative path name.
51 * This path contains the file name.
53 * @return string the relative path name
55 public function getRelativePathname()
57 return $this->relativePathname;
61 * Returns the contents of the file.
63 * @return string the contents of the file
65 * @throws \RuntimeException
67 public function getContents()
69 $level = error_reporting(0);
70 $content = file_get_contents($this->getPathname());
71 error_reporting($level);
72 if (false === $content) {
73 $error = error_get_last();
74 throw new \RuntimeException($error['message']);