FIX: Telefono sobre rango maximo de integer en MySQL
This commit is contained in:
28
app/src/Service/Valor/Phone.php
Normal file
28
app/src/Service/Valor/Phone.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Valor;
|
||||
|
||||
class Phone
|
||||
{
|
||||
public function toDatabase(?string $phone): ?int
|
||||
{
|
||||
if ($phone === null) {
|
||||
return null;
|
||||
}
|
||||
return (int) str_replace([' ', '+'], '', $phone) ?? null;
|
||||
}
|
||||
public function toDisplay(?int $phone): ?string
|
||||
{
|
||||
if ($phone === null) {
|
||||
return null;
|
||||
}
|
||||
$parts = preg_split('/(?=<country>\d{2})?(?=<area>\d)(?=<first>\d{4})(?=<last>\d{4})/', $phone);
|
||||
$output = [];
|
||||
if (array_key_exists('country', $parts)) {
|
||||
$output [] = "+{$parts[0]}";
|
||||
}
|
||||
$output [] = $parts[1] ?? '';
|
||||
$output [] = $parts[2] ?? '';
|
||||
$output [] = $parts[3] ?? '';
|
||||
return implode(' ', $output);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user