nur-sery/src/os/file/_File.php

32 lines
955 B
PHP
Raw Normal View History

2023-12-31 22:28:03 +04:00
<?php
namespace nur\sery\os\file;
use nur\sery\os\IOException;
use nur\sery\web\http;
abstract class _File extends Stream {
function __construct($fd, bool $close, bool $throwOnError=true, ?bool $allowLocking=null) {
parent::__construct($fd, $close, $throwOnError, $allowLocking);
}
/** @var string */
protected $file;
/** @var string */
protected $mode;
function getResource() {
if ($this->fd === null && $this->file !== null) {
$this->fd = IOException::ensure_value(@fopen($this->file, $this->mode));
}
return parent::getResource();
}
/** streamer le contenu du fichier en sortie */
function readfile(?string $contentType=null, ?string $charset=null, ?string $filename=null, string $disposition=null): bool {
if ($contentType !== null) http::content_type($contentType, $charset);
if ($filename !== null) http::download_as($filename, $disposition);
return readfile($this->file) !== false;
}
}