modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-03-25 11:59:32 +04:00
parent 38e90f752f
commit 797e56dee5
7 changed files with 15 additions and 13 deletions

View File

@ -2,6 +2,7 @@
namespace nur\sery\cli;
use nulib\str;
use nur\A;
use nur\sery\php\func;
use nur\sery\ref\cli\ref_args;
use nur\sery\values\akey;

View File

@ -1,6 +1,7 @@
<?php
namespace nur\sery\cli;
use nur\A;
use nur\sery\php\func;
/**

View File

@ -26,7 +26,7 @@ class IOException extends RuntimeException {
else throw self::generic_error($prefix);
}
static final function ensure_value($value, bool $throw=true, $invalid=false) {
static final function ensure_valid($value, bool $throw=true, $invalid=false) {
if (!$throw) return null;
elseif ($value !== $invalid) return $value;
else throw self::error();

View File

@ -21,7 +21,7 @@ class FileWriter extends _File {
} else {
$file = $output;
if ($mode === null) $mode = static::DEFAULT_MODE;
IOException::ensure_value(sh::mkdirof($file));
IOException::ensure_valid(sh::mkdirof($file));
$this->file = $file;
$this->mode = $mode;
$fd = $this->open();

View File

@ -78,7 +78,7 @@ class Stream extends AbstractIterator implements IReader, IWriter {
function fstat(bool $reload=false): array {
if ($this->stat === null || $reload) {
$fd = $this->getResource();
$this->stat = IOException::ensure_value(fstat($fd), $this->throwOnError);
$this->stat = IOException::ensure_valid(fstat($fd), $this->throwOnError);
}
return $this->stat;
}
@ -90,7 +90,7 @@ class Stream extends AbstractIterator implements IReader, IWriter {
/** @throws IOException */
function ftell(): int {
$fd = $this->getResource();
return IOException::ensure_value(ftell($fd), $this->throwOnError);
return IOException::ensure_valid(ftell($fd), $this->throwOnError);
}
/**
@ -99,7 +99,7 @@ class Stream extends AbstractIterator implements IReader, IWriter {
*/
function fseek(int $offset, int $whence=SEEK_SET): int {
$fd = $this->getResource();
IOException::ensure_value(fseek($fd, $offset, $whence), $this->throwOnError, -1);
IOException::ensure_valid(fseek($fd, $offset, $whence), $this->throwOnError, -1);
return $this->ftell();
}
@ -137,7 +137,7 @@ class Stream extends AbstractIterator implements IReader, IWriter {
/** @throws IOException */
function fread(int $length): string {
$fd = $this->getResource();
return IOException::ensure_value(fread($fd, $length), $this->throwOnError);
return IOException::ensure_valid(fread($fd, $length), $this->throwOnError);
}
/**
@ -155,7 +155,7 @@ class Stream extends AbstractIterator implements IReader, IWriter {
/** @throws IOException */
function fpassthru(): int {
$fd = $this->getResource();
return IOException::ensure_value(fpassthru($fd), $this->throwOnError);
return IOException::ensure_valid(fpassthru($fd), $this->throwOnError);
}
/**
@ -214,7 +214,7 @@ class Stream extends AbstractIterator implements IReader, IWriter {
$useLocking = $this->useLocking;
if ($useLocking && !$lockedByCanRead) $this->lock(LOCK_SH);
try {
return IOException::ensure_value(stream_get_contents($this->fd), $this->throwOnError);
return IOException::ensure_valid(stream_get_contents($this->fd), $this->throwOnError);
} finally {
if ($useLocking) $this->unlock($close);
elseif ($close) $this->close();
@ -249,20 +249,20 @@ class Stream extends AbstractIterator implements IReader, IWriter {
$fd = $this->getResource();
if ($length === null) $r = fwrite($fd, $data);
else $r = fwrite($fd, $data, $length);
return IOException::ensure_value($r, $this->throwOnError);
return IOException::ensure_valid($r, $this->throwOnError);
}
/** @throws IOException */
function fflush(): self {
$fd = $this->getResource();
IOException::ensure_value(fflush($fd), $this->throwOnError);
IOException::ensure_valid(fflush($fd), $this->throwOnError);
return $this;
}
/** @throws IOException */
function ftruncate(int $size): self {
$fd = $this->getResource();
IOException::ensure_value(ftruncate($fd, $size), $this->throwOnError);
IOException::ensure_valid(ftruncate($fd, $size), $this->throwOnError);
return $this;
}

View File

@ -16,7 +16,7 @@ abstract class _File extends Stream {
protected $mode;
protected function open() {
return IOException::ensure_value(@fopen($this->file, $this->mode));
return IOException::ensure_valid(@fopen($this->file, $this->mode));
}
function getResource() {

View File

@ -123,7 +123,7 @@ class path {
static final function realpath($path): ?string {
if ($path === null || $path === false) return null;
$path = strval($path);
return IOException::ensure_value(realpath($path));
return IOException::ensure_valid(realpath($path));
}
/**