2011-02-15 23:18:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-02-15 23:18:23 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\Finder;
|
|
|
|
|
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Extends \SplFileInfo to support relative paths.
|
2011-02-15 23:18:23 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2011-02-15 23:18:23 +00:00
|
|
|
*/
|
|
|
|
class SplFileInfo extends \SplFileInfo
|
|
|
|
{
|
2011-03-08 19:54:22 +00:00
|
|
|
private $relativePath;
|
|
|
|
private $relativePathname;
|
2011-02-15 23:18:23 +00:00
|
|
|
|
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Constructor.
|
2011-02-15 23:18:23 +00:00
|
|
|
*
|
2011-04-23 16:05:44 +01:00
|
|
|
* @param string $file The file name
|
|
|
|
* @param string $relativePath The relative path
|
|
|
|
* @param string $relativePathname The relative path name
|
2011-02-15 23:18:23 +00:00
|
|
|
*/
|
|
|
|
public function __construct($file, $relativePath, $relativePathname)
|
|
|
|
{
|
|
|
|
parent::__construct($file);
|
|
|
|
$this->relativePath = $relativePath;
|
|
|
|
$this->relativePathname = $relativePathname;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Returns the relative path.
|
2011-02-15 23:18:23 +00:00
|
|
|
*
|
|
|
|
* @return string the relative path
|
|
|
|
*/
|
|
|
|
public function getRelativePath()
|
|
|
|
{
|
|
|
|
return $this->relativePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Returns the relative path name.
|
2011-02-15 23:18:23 +00:00
|
|
|
*
|
|
|
|
* @return string the relative path name
|
|
|
|
*/
|
|
|
|
public function getRelativePathname()
|
|
|
|
{
|
|
|
|
return $this->relativePathname;
|
|
|
|
}
|
2012-05-19 09:42:27 +01:00
|
|
|
|
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Returns the contents of the file.
|
2012-05-19 09:42:27 +01:00
|
|
|
*
|
|
|
|
* @return string the contents of the file
|
2012-12-16 12:02:54 +00:00
|
|
|
*
|
|
|
|
* @throws \RuntimeException
|
2012-05-19 09:42:27 +01:00
|
|
|
*/
|
|
|
|
public function getContents()
|
|
|
|
{
|
2012-12-10 12:46:43 +00:00
|
|
|
$level = error_reporting(0);
|
2013-06-10 19:35:46 +01:00
|
|
|
$content = file_get_contents($this->getPathname());
|
2012-12-10 12:46:43 +00:00
|
|
|
error_reporting($level);
|
|
|
|
if (false === $content) {
|
|
|
|
$error = error_get_last();
|
|
|
|
throw new \RuntimeException($error['message']);
|
|
|
|
}
|
2012-07-09 16:06:57 +01:00
|
|
|
|
2012-12-10 12:46:43 +00:00
|
|
|
return $content;
|
2012-05-19 09:42:27 +01:00
|
|
|
}
|
2011-03-08 19:54:22 +00:00
|
|
|
}
|