144 lines
4.0 KiB
PHP
144 lines
4.0 KiB
PHP
|
<?php
|
||
|
namespace nur\mapper\item;
|
||
|
|
||
|
use nur\A;
|
||
|
use nur\base;
|
||
|
use nur\str;
|
||
|
|
||
|
/**
|
||
|
* Class StringMapper: un mapper qui fait des opérations sur des chaines
|
||
|
*
|
||
|
* --autogen-properties-and-methods--
|
||
|
* @method array|null setActions(?array $value)
|
||
|
* @method bool setMarkedOnly(bool $value)
|
||
|
*/
|
||
|
class StringMapper extends AbstractStringMapper {
|
||
|
protected static function del_prefix($value, ?string $prefix) {
|
||
|
return str::without_prefix($prefix, $value);
|
||
|
}
|
||
|
|
||
|
protected static function del_suffix($value, ?string $suffix) {
|
||
|
return str::without_suffix($suffix, $value);
|
||
|
}
|
||
|
|
||
|
protected static function left($value, int $length) {
|
||
|
if (base::z($value)) return $value;
|
||
|
return substr(strval($value), 0, $length);
|
||
|
}
|
||
|
|
||
|
protected static function right($value, int $length) {
|
||
|
if (base::z($value)) return $value;
|
||
|
return substr(strval($value), -$length);
|
||
|
}
|
||
|
|
||
|
protected static function substr($value, int $offset, ?int $length) {
|
||
|
if (base::z($value)) return $value;
|
||
|
$args = [strval($value), $offset];
|
||
|
if ($length !== null) $args[] = $length;
|
||
|
return substr(...$args);
|
||
|
}
|
||
|
|
||
|
protected static function str_replace($value, ?string $from, ?string $to, int $limit) {
|
||
|
if (base::z($value)) return $value;
|
||
|
if ($limit == -1) return str_replace($from, $to, strval($value));
|
||
|
$value = strval($value);
|
||
|
$index = 0;
|
||
|
$flength = strlen($from);
|
||
|
while ($limit-- > 0) {
|
||
|
$pos = strpos($value, $from, $index);
|
||
|
if ($pos === false) break;
|
||
|
$value = substr($value, 0, $pos).$to.substr($value, $pos + $flength);
|
||
|
$index = $pos + $flength + 1;
|
||
|
}
|
||
|
return $value;
|
||
|
}
|
||
|
|
||
|
protected static function join($value, string $sep): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return str::join($sep, A::with($value));
|
||
|
}
|
||
|
|
||
|
protected static function trunc($value, int $length, bool $ellips=false, ?string $suffix=null): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return str::trunc(strval($value), $length, $ellips, $suffix);
|
||
|
}
|
||
|
|
||
|
protected static function trim($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return str::trim(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function ltrim($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return str::ltrim(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function rtrim($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return str::rtrim(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function lower($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return str::lower(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function lower1($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return str::lower1(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function upper($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return str::upper(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function upper1($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return str::upper1(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function upperw($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return str::upperw(strval($value));
|
||
|
}
|
||
|
|
||
|
#############################################################################
|
||
|
const _AUTOGEN_CONSTS = [
|
||
|
"" => [self::class, "_autogen_consts"],
|
||
|
];
|
||
|
const _AUTOGEN_LITERALS = /*autogen*/[
|
||
|
[
|
||
|
\nur\b\params\parametrable_utils::class,
|
||
|
'\\nur\\b\\params\\parametrable_utils::class',
|
||
|
],
|
||
|
[
|
||
|
self::PARAMETRABLE_PARAMS_SCHEMA,
|
||
|
'self::PARAMETRABLE_PARAMS_SCHEMA',
|
||
|
],
|
||
|
];
|
||
|
const _AUTOGEN_METHODS = /*autogen*/[
|
||
|
[
|
||
|
\nur\b\params\parametrable_utils::class,
|
||
|
'_autogen_methods_getters',
|
||
|
self::PARAMETRABLE_PARAMS_SCHEMA,
|
||
|
null,
|
||
|
],
|
||
|
[
|
||
|
\nur\b\params\parametrable_utils::class,
|
||
|
'_autogen_methods_setters',
|
||
|
self::PARAMETRABLE_PARAMS_SCHEMA,
|
||
|
null,
|
||
|
],
|
||
|
];
|
||
|
const _AUTO_GETTERS = /*autogen*/[
|
||
|
'getActions' => 'actions',
|
||
|
'isMarkedOnly' => 'marked_only',
|
||
|
];
|
||
|
const _AUTO_SETTERS = /*autogen*/[
|
||
|
'setActions' => 'actions',
|
||
|
'setMarkedOnly' => 'marked_only',
|
||
|
];
|
||
|
#--autogen-dynamic--
|
||
|
}
|