friendship ended with social-app. php is my new best friend
at main 1.3 kB view raw
1<?php 2 3/** 4 * This file is part of the Nette Framework (https://nette.org) 5 * Copyright (c) 2004 David Grudl (https://davidgrudl.com) 6 */ 7 8declare(strict_types=1); 9 10namespace Nette\Utils; 11 12use Nette; 13use const DIRECTORY_SEPARATOR; 14 15 16/** 17 * Represents the file or directory returned by the Finder. 18 * @internal do not create instances directly 19 */ 20final class FileInfo extends \SplFileInfo 21{ 22 private string $relativePath; 23 24 25 public function __construct(string $file, string $relativePath = '') 26 { 27 parent::__construct($file); 28 $this->setInfoClass(static::class); 29 $this->relativePath = $relativePath; 30 } 31 32 33 /** 34 * Returns the relative directory path. 35 */ 36 public function getRelativePath(): string 37 { 38 return $this->relativePath; 39 } 40 41 42 /** 43 * Returns the relative path including file name. 44 */ 45 public function getRelativePathname(): string 46 { 47 return ($this->relativePath === '' ? '' : $this->relativePath . DIRECTORY_SEPARATOR) 48 . $this->getBasename(); 49 } 50 51 52 /** 53 * Returns the contents of the file. 54 * @throws Nette\IOException 55 */ 56 public function read(): string 57 { 58 return FileSystem::read($this->getPathname()); 59 } 60 61 62 /** 63 * Writes the contents to the file. 64 * @throws Nette\IOException 65 */ 66 public function write(string $content): void 67 { 68 FileSystem::write($this->getPathname(), $content); 69 } 70}