modifs.mineures sans commentaires
This commit is contained in:
parent
38e90f752f
commit
797e56dee5
|
@ -2,6 +2,7 @@
|
||||||
namespace nur\sery\cli;
|
namespace nur\sery\cli;
|
||||||
|
|
||||||
use nulib\str;
|
use nulib\str;
|
||||||
|
use nur\A;
|
||||||
use nur\sery\php\func;
|
use nur\sery\php\func;
|
||||||
use nur\sery\ref\cli\ref_args;
|
use nur\sery\ref\cli\ref_args;
|
||||||
use nur\sery\values\akey;
|
use nur\sery\values\akey;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace nur\sery\cli;
|
namespace nur\sery\cli;
|
||||||
|
|
||||||
|
use nur\A;
|
||||||
use nur\sery\php\func;
|
use nur\sery\php\func;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,7 +26,7 @@ class IOException extends RuntimeException {
|
||||||
else throw self::generic_error($prefix);
|
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;
|
if (!$throw) return null;
|
||||||
elseif ($value !== $invalid) return $value;
|
elseif ($value !== $invalid) return $value;
|
||||||
else throw self::error();
|
else throw self::error();
|
||||||
|
|
|
@ -21,7 +21,7 @@ class FileWriter extends _File {
|
||||||
} else {
|
} else {
|
||||||
$file = $output;
|
$file = $output;
|
||||||
if ($mode === null) $mode = static::DEFAULT_MODE;
|
if ($mode === null) $mode = static::DEFAULT_MODE;
|
||||||
IOException::ensure_value(sh::mkdirof($file));
|
IOException::ensure_valid(sh::mkdirof($file));
|
||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
$this->mode = $mode;
|
$this->mode = $mode;
|
||||||
$fd = $this->open();
|
$fd = $this->open();
|
||||||
|
|
|
@ -78,7 +78,7 @@ class Stream extends AbstractIterator implements IReader, IWriter {
|
||||||
function fstat(bool $reload=false): array {
|
function fstat(bool $reload=false): array {
|
||||||
if ($this->stat === null || $reload) {
|
if ($this->stat === null || $reload) {
|
||||||
$fd = $this->getResource();
|
$fd = $this->getResource();
|
||||||
$this->stat = IOException::ensure_value(fstat($fd), $this->throwOnError);
|
$this->stat = IOException::ensure_valid(fstat($fd), $this->throwOnError);
|
||||||
}
|
}
|
||||||
return $this->stat;
|
return $this->stat;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ class Stream extends AbstractIterator implements IReader, IWriter {
|
||||||
/** @throws IOException */
|
/** @throws IOException */
|
||||||
function ftell(): int {
|
function ftell(): int {
|
||||||
$fd = $this->getResource();
|
$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 {
|
function fseek(int $offset, int $whence=SEEK_SET): int {
|
||||||
$fd = $this->getResource();
|
$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();
|
return $this->ftell();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ class Stream extends AbstractIterator implements IReader, IWriter {
|
||||||
/** @throws IOException */
|
/** @throws IOException */
|
||||||
function fread(int $length): string {
|
function fread(int $length): string {
|
||||||
$fd = $this->getResource();
|
$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 */
|
/** @throws IOException */
|
||||||
function fpassthru(): int {
|
function fpassthru(): int {
|
||||||
$fd = $this->getResource();
|
$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;
|
$useLocking = $this->useLocking;
|
||||||
if ($useLocking && !$lockedByCanRead) $this->lock(LOCK_SH);
|
if ($useLocking && !$lockedByCanRead) $this->lock(LOCK_SH);
|
||||||
try {
|
try {
|
||||||
return IOException::ensure_value(stream_get_contents($this->fd), $this->throwOnError);
|
return IOException::ensure_valid(stream_get_contents($this->fd), $this->throwOnError);
|
||||||
} finally {
|
} finally {
|
||||||
if ($useLocking) $this->unlock($close);
|
if ($useLocking) $this->unlock($close);
|
||||||
elseif ($close) $this->close();
|
elseif ($close) $this->close();
|
||||||
|
@ -249,20 +249,20 @@ class Stream extends AbstractIterator implements IReader, IWriter {
|
||||||
$fd = $this->getResource();
|
$fd = $this->getResource();
|
||||||
if ($length === null) $r = fwrite($fd, $data);
|
if ($length === null) $r = fwrite($fd, $data);
|
||||||
else $r = fwrite($fd, $data, $length);
|
else $r = fwrite($fd, $data, $length);
|
||||||
return IOException::ensure_value($r, $this->throwOnError);
|
return IOException::ensure_valid($r, $this->throwOnError);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @throws IOException */
|
/** @throws IOException */
|
||||||
function fflush(): self {
|
function fflush(): self {
|
||||||
$fd = $this->getResource();
|
$fd = $this->getResource();
|
||||||
IOException::ensure_value(fflush($fd), $this->throwOnError);
|
IOException::ensure_valid(fflush($fd), $this->throwOnError);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @throws IOException */
|
/** @throws IOException */
|
||||||
function ftruncate(int $size): self {
|
function ftruncate(int $size): self {
|
||||||
$fd = $this->getResource();
|
$fd = $this->getResource();
|
||||||
IOException::ensure_value(ftruncate($fd, $size), $this->throwOnError);
|
IOException::ensure_valid(ftruncate($fd, $size), $this->throwOnError);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ abstract class _File extends Stream {
|
||||||
protected $mode;
|
protected $mode;
|
||||||
|
|
||||||
protected function open() {
|
protected function open() {
|
||||||
return IOException::ensure_value(@fopen($this->file, $this->mode));
|
return IOException::ensure_valid(@fopen($this->file, $this->mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getResource() {
|
function getResource() {
|
||||||
|
|
|
@ -123,7 +123,7 @@ class path {
|
||||||
static final function realpath($path): ?string {
|
static final function realpath($path): ?string {
|
||||||
if ($path === null || $path === false) return null;
|
if ($path === null || $path === false) return null;
|
||||||
$path = strval($path);
|
$path = strval($path);
|
||||||
return IOException::ensure_value(realpath($path));
|
return IOException::ensure_valid(realpath($path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue