support de téléphone avec label

This commit is contained in:
Jephté Clain 2024-04-29 16:39:43 +04:00
parent 2a26b7db8d
commit 26edd874df
2 changed files with 30 additions and 2 deletions

23
nur_src/ldap/labels.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace nur\ldap;
use nur\str;
class labels {
static function strip(?string &$value, ?string &$label=null): void {
if ($value === null) return;
if (preg_match('/^(\{[^}]*})/', $value, $ms, PREG_OFFSET_CAPTURE)) {
$label = $ms[1][0];
$value = substr($value, $ms[1][1] + strlen($label));
}
}
static function add(?string $value, ?string $label): ?string {
if ($value === null) return null;
if ($label !== null) {
str::add_prefix($label, "{");
str::add_suffix($label, "}");
}
return "$label$value";
}
}

View File

@ -2,6 +2,7 @@
namespace nur\ldap\syntaxes;
use nur\data\types\TelephoneType;
use nur\ldap\labels;
class TelephoneSyntax extends StringSyntax {
function __construct() {
@ -14,11 +15,15 @@ class TelephoneSyntax extends StringSyntax {
function php2ldap($value): ?string {
$value = parent::php2ldap($value);
if ($value === null) return null;
labels::strip($value, $label);
$type = $this->type;
return $type->ensureInternational($type->with($value));
$value = $type->ensureInternational($type->with($value));
return labels::add($value, $label);
}
function ldap2php(string $value): string {
return $this->type->ensureLocal($value);
labels::strip($value, $label);
$value = $this->type->ensureLocal($value);
return labels::add($value, $label);
}
}