145 lines
4.0 KiB
PHP
145 lines
4.0 KiB
PHP
|
<?php
|
||
|
namespace nur\mapper\item;
|
||
|
|
||
|
use nur\A;
|
||
|
use nur\base;
|
||
|
use nur\str;
|
||
|
use nur\txt;
|
||
|
|
||
|
/**
|
||
|
* Class TextMapper: 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 TextMapper extends AbstractStringMapper {
|
||
|
protected static function del_prefix($value, ?string $prefix) {
|
||
|
return txt::without_prefix($prefix, $value);
|
||
|
}
|
||
|
|
||
|
protected static function del_suffix($value, ?string $suffix) {
|
||
|
return txt::without_suffix($suffix, $value);
|
||
|
}
|
||
|
|
||
|
protected static function left($value, int $length) {
|
||
|
if (base::z($value)) return $value;
|
||
|
return mb_substr(strval($value), 0, $length);
|
||
|
}
|
||
|
|
||
|
protected static function right($value, int $length) {
|
||
|
if (base::z($value)) return $value;
|
||
|
return mb_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 mb_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 = mb_strlen($from);
|
||
|
while ($limit-- > 0) {
|
||
|
$pos = mb_strpos($value, $from, $index);
|
||
|
if ($pos === false) break;
|
||
|
$value = mb_substr($value, 0, $pos).$to.mb_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 txt::trunc(strval($value), $length, $ellips, $suffix);
|
||
|
}
|
||
|
|
||
|
protected static function trim($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return txt::trim(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function ltrim($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return txt::ltrim(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function rtrim($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return txt::rtrim(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function lower($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return txt::lower(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function lower1($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return txt::lower1(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function upper($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return txt::upper(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function upper1($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return txt::upper1(strval($value));
|
||
|
}
|
||
|
|
||
|
protected static function upperw($value): string {
|
||
|
if (base::z($value)) return $value;
|
||
|
return txt::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--
|
||
|
}
|