Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Finder; Chris@0: Chris@0: /** Chris@0: * Extends \SplFileInfo to support relative paths. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class SplFileInfo extends \SplFileInfo Chris@0: { Chris@0: private $relativePath; Chris@0: private $relativePathname; Chris@0: Chris@0: /** Chris@0: * @param string $file The file name Chris@0: * @param string $relativePath The relative path Chris@0: * @param string $relativePathname The relative path name Chris@0: */ Chris@0: public function __construct($file, $relativePath, $relativePathname) Chris@0: { Chris@0: parent::__construct($file); Chris@0: $this->relativePath = $relativePath; Chris@0: $this->relativePathname = $relativePathname; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the relative path. Chris@0: * Chris@0: * This path does not contain the file name. Chris@0: * Chris@0: * @return string the relative path Chris@0: */ Chris@0: public function getRelativePath() Chris@0: { Chris@0: return $this->relativePath; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the relative path name. Chris@0: * Chris@0: * This path contains the file name. Chris@0: * Chris@0: * @return string the relative path name Chris@0: */ Chris@0: public function getRelativePathname() Chris@0: { Chris@0: return $this->relativePathname; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the contents of the file. Chris@0: * Chris@0: * @return string the contents of the file Chris@0: * Chris@0: * @throws \RuntimeException Chris@0: */ Chris@0: public function getContents() Chris@0: { Chris@16: set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; }); Chris@0: $content = file_get_contents($this->getPathname()); Chris@16: restore_error_handler(); Chris@0: if (false === $content) { Chris@16: throw new \RuntimeException($error); Chris@0: } Chris@0: Chris@0: return $content; Chris@0: } Chris@0: }