58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace VeruA\DomainObjects\ValueObjects;
|
|
|
|
/**
|
|
* An implementation of a Street composed by name and number
|
|
*/
|
|
class Street extends Varchar
|
|
{
|
|
private string $name;
|
|
private string $number;
|
|
|
|
// in() {{{
|
|
/**
|
|
*
|
|
*/
|
|
public function in($value)
|
|
{
|
|
$this->value = (string)trim($value);
|
|
preg_match('/^(?P<name>(\d*\D+ (\d* )?)+)(?P<number>\d+.*)$/', $this->value, $match);
|
|
$this->name = $match['name'];
|
|
$this->number = $match['number'];
|
|
} // }}}
|
|
|
|
public function __get(string $field): string
|
|
{
|
|
switch ($field)
|
|
{
|
|
case 'name':
|
|
return $this->name;
|
|
case 'number':
|
|
return $this->number;
|
|
default:
|
|
throw new \OutOfRangeException('A Street Object is composed of only street->name and street->number');
|
|
}
|
|
}
|
|
|
|
public function __set(string $field, string $value)
|
|
{
|
|
switch ($field)
|
|
{
|
|
case 'name':
|
|
$this->name = trim($value);
|
|
break;
|
|
case 'number':
|
|
$this->number = trim($value);
|
|
break;
|
|
default:
|
|
throw new \OutOfRangeException('A Street Object is composed of only street->name and street->number');
|
|
}
|
|
$this->value = "$this->name $this->value";
|
|
}
|
|
|
|
}
|
|
|
|
/* jEdit buffer local properties {{{
|
|
* :folding=explicit:collapseFolds=1:
|
|
}}}*/
|