You are here

class SplFileInfo in Database Sanitize 7

Extends \SplFileInfo to support relative paths.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of SplFileInfo

1 file declares its use of SplFileInfo
RecursiveDirectoryIterator.php in vendor/symfony/finder/Iterator/RecursiveDirectoryIterator.php

File

vendor/symfony/finder/SplFileInfo.php, line 19

Namespace

Symfony\Component\Finder
View source
class SplFileInfo extends \SplFileInfo {
  private $relativePath;
  private $relativePathname;

  /**
   * @param string $file             The file name
   * @param string $relativePath     The relative path
   * @param string $relativePathname The relative path name
   */
  public function __construct($file, $relativePath, $relativePathname) {
    parent::__construct($file);
    $this->relativePath = $relativePath;
    $this->relativePathname = $relativePathname;
  }

  /**
   * Returns the relative path.
   *
   * This path does not contain the file name.
   *
   * @return string the relative path
   */
  public function getRelativePath() {
    return $this->relativePath;
  }

  /**
   * Returns the relative path name.
   *
   * This path contains the file name.
   *
   * @return string the relative path name
   */
  public function getRelativePathname() {
    return $this->relativePathname;
  }

  /**
   * Returns the contents of the file.
   *
   * @return string the contents of the file
   *
   * @throws \RuntimeException
   */
  public function getContents() {
    set_error_handler(function ($type, $msg) use (&$error) {
      $error = $msg;
    });
    $content = file_get_contents($this
      ->getPathname());
    restore_error_handler();
    if (false === $content) {
      throw new \RuntimeException($error);
    }
    return $content;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SplFileInfo::$relativePath private property Overrides SplFileInfo::$relativePath 1
SplFileInfo::$relativePathname private property Overrides SplFileInfo::$relativePathname 1
SplFileInfo::getContents public function Returns the contents of the file. Overrides SplFileInfo::getContents 1
SplFileInfo::getRelativePath public function Returns the relative path. Overrides SplFileInfo::getRelativePath 1
SplFileInfo::getRelativePathname public function Returns the relative path name. Overrides SplFileInfo::getRelativePathname 1
SplFileInfo::__construct public function Overrides SplFileInfo::__construct 1