modifs.mineures sans commentaires
This commit is contained in:
parent
c5b9812c82
commit
3aec24ddb3
@ -86,6 +86,12 @@ class cv {
|
|||||||
$b = $tmp;
|
$b = $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** cloner une valeur */
|
||||||
|
static final function clone($value) {
|
||||||
|
if (is_object($value)) $value = clone $value;
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
/** mettre à jour $dest avec $value si $cond($value) est vrai */
|
/** mettre à jour $dest avec $value si $cond($value) est vrai */
|
||||||
@ -197,19 +203,29 @@ class cv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* retourner [$bool, $string, $array] initialisés chacun en fonction du type
|
* retourner [$bool, $scalar, $array] initialisés chacun en fonction du type
|
||||||
* de $value.
|
* de $value.
|
||||||
*
|
*
|
||||||
* @throws ValueException si $value n'est d'aucun de ces types
|
* @throws ValueException si $value n'est d'aucun de ces types
|
||||||
*/
|
*/
|
||||||
static final function check_bsa($value, ?string $prefix=null, bool $throw_exception=true): array {
|
static final function check_bsa($value, ?string $prefix=null, bool $throw_exception=true): array {
|
||||||
$bool = is_bool($value)? $value : null;
|
$bool = is_bool($value)? $value : null;
|
||||||
$string = is_string($value)? $value : null;
|
$scalar = !is_bool($value) && is_scalar($value)? $value : null;
|
||||||
$array = is_array($value)? $value : null;
|
$array = is_array($value)? $value : null;
|
||||||
if ($bool === null && $string === null && $array === null && $throw_exception) {
|
if ($bool === null && $scalar === null && $array === null && $throw_exception) {
|
||||||
throw ValueException::invalid_kind($value, "value", $prefix);
|
throw ValueException::invalid_kind($value, "value", $prefix);
|
||||||
} else {
|
} else {
|
||||||
return [$bool, $string, $array];
|
return [$bool, $scalar, $array];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static final function subclass_of($value, $class): bool {
|
||||||
|
if (is_string($value)) {
|
||||||
|
return $value === $class || is_subclass_of($value, $class);
|
||||||
|
} elseif (is_object($value)) {
|
||||||
|
return $value instanceof $class;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,8 +299,8 @@ class Stream extends AbstractIterator implements IReader, IWriter {
|
|||||||
|
|
||||||
/** retourner le contenu du fichier sous forme de chaine */
|
/** retourner le contenu du fichier sous forme de chaine */
|
||||||
function getContents(bool $close=true, bool $alreadyLocked=false): string {
|
function getContents(bool $close=true, bool $alreadyLocked=false): string {
|
||||||
$useLocking = $this->useLocking;
|
$useLocking = $this->useLocking && !$alreadyLocked;
|
||||||
if ($useLocking && !$alreadyLocked) $this->lock(LOCK_SH);
|
if ($useLocking) $this->lock(LOCK_SH);
|
||||||
try {
|
try {
|
||||||
return IOException::ensure_valid(stream_get_contents($this->fd), $this->throwOnError);
|
return IOException::ensure_valid(stream_get_contents($this->fd), $this->throwOnError);
|
||||||
} finally {
|
} finally {
|
||||||
@ -380,7 +380,9 @@ class Stream extends AbstractIterator implements IReader, IWriter {
|
|||||||
/** @throws IOException */
|
/** @throws IOException */
|
||||||
function ftruncate(int $size=0, bool $rewind=true): self {
|
function ftruncate(int $size=0, bool $rewind=true): self {
|
||||||
$fd = $this->getResource();
|
$fd = $this->getResource();
|
||||||
IOException::ensure_valid(ftruncate($fd, $size), $this->throwOnError);
|
$r = ftruncate($fd, $size);
|
||||||
|
$this->stat = null;
|
||||||
|
IOException::ensure_valid($r, $this->throwOnError);
|
||||||
if ($rewind) rewind($fd);
|
if ($rewind) rewind($fd);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -390,6 +392,7 @@ 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);
|
||||||
|
$this->stat = null;
|
||||||
return IOException::ensure_valid($r, $this->throwOnError);
|
return IOException::ensure_valid($r, $this->throwOnError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,9 +406,13 @@ class Stream extends AbstractIterator implements IReader, IWriter {
|
|||||||
$line[] = strval($col);
|
$line[] = strval($col);
|
||||||
}
|
}
|
||||||
$line = implode($sep, $line);
|
$line = implode($sep, $line);
|
||||||
IOException::ensure_valid(fwrite($fd, "$line\n"), $this->throwOnError);
|
$r = fwrite($fd, "$line\n");
|
||||||
|
$this->stat = null;
|
||||||
|
IOException::ensure_valid($r, $this->throwOnError);
|
||||||
} else {
|
} else {
|
||||||
IOException::ensure_valid(fputcsv($fd, $row, $params[0], $params[1], $params[2]), $this->throwOnError);
|
$r = fputcsv($fd, $row, $params[0], $params[1], $params[2]);
|
||||||
|
$this->stat = null;
|
||||||
|
IOException::ensure_valid($r, $this->throwOnError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,8 +478,8 @@ class Stream extends AbstractIterator implements IReader, IWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function putContents(string $contents, bool $close=true, bool $alreadyLocked=false): void {
|
function putContents(string $contents, bool $close=true, bool $alreadyLocked=false): void {
|
||||||
$useLocking = $this->useLocking;
|
$useLocking = $this->useLocking && !$alreadyLocked;
|
||||||
if ($useLocking && !$alreadyLocked) $this->lock(LOCK_EX);
|
if ($useLocking) $this->lock(LOCK_EX);
|
||||||
try {
|
try {
|
||||||
$this->fwrite($contents);
|
$this->fwrite($contents);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -29,7 +29,7 @@ class DateInterval extends \DateInterval {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function __construct($duration) {
|
function __construct($duration) {
|
||||||
if (is_int($duration)) $duration = "PT${duration}S";
|
if (is_numeric($duration)) $duration = "PT${duration}S";
|
||||||
if ($duration instanceof \DateInterval) {
|
if ($duration instanceof \DateInterval) {
|
||||||
$this->y = $duration->y;
|
$this->y = $duration->y;
|
||||||
$this->m = $duration->m;
|
$this->m = $duration->m;
|
||||||
|
@ -3,6 +3,7 @@ namespace nulib\php\time;
|
|||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
use nulib\ValueException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Delay: une durée jusqu'à un moment destination. le moment destination
|
* Class Delay: une durée jusqu'à un moment destination. le moment destination
|
||||||
@ -115,6 +116,10 @@ class Delay {
|
|||||||
$this->repr = $repr;
|
$this->repr = $repr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __clone() {
|
||||||
|
$this->dest = clone $this->dest;
|
||||||
|
}
|
||||||
|
|
||||||
function __serialize(): array {
|
function __serialize(): array {
|
||||||
return [$this->dest, $this->repr];
|
return [$this->dest, $this->repr];
|
||||||
}
|
}
|
||||||
@ -130,7 +135,7 @@ class Delay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addDuration($duration) {
|
function addDuration($duration) {
|
||||||
if (is_int($duration) && $duration < 0) {
|
if (is_numeric($duration) && $duration < 0) {
|
||||||
$this->dest->sub(DateInterval::with(-$duration));
|
$this->dest->sub(DateInterval::with(-$duration));
|
||||||
} else {
|
} else {
|
||||||
$this->dest->add(DateInterval::with($duration));
|
$this->dest->add(DateInterval::with($duration));
|
||||||
@ -138,7 +143,7 @@ class Delay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function subDuration($duration) {
|
function subDuration($duration) {
|
||||||
if (is_int($duration) && $duration < 0) {
|
if (is_numeric($duration) && $duration < 0) {
|
||||||
$this->dest->add(DateInterval::with(-$duration));
|
$this->dest->add(DateInterval::with(-$duration));
|
||||||
} else {
|
} else {
|
||||||
$this->dest->sub(DateInterval::with($duration));
|
$this->dest->sub(DateInterval::with($duration));
|
||||||
|
Reference in New Issue
Block a user