| 1 | <?php |
||
| 7 | class Part |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * A store of the name segments. |
||
| 11 | * |
||
| 12 | * @var array |
||
| 13 | */ |
||
| 14 | protected $segments = []; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Creates a new part given the string part. |
||
| 18 | * |
||
| 19 | * @param string $string The name part. |
||
| 20 | */ |
||
| 21 | public function __construct($string) |
||
| 22 | { |
||
| 23 | $parts = S::create($string)->split(' '); |
||
| 24 | $segments = array_filter($parts, function($part) { |
||
| 25 | return S::create($part)->trim()->length() > 0; |
||
| 26 | }); |
||
| 27 | |||
| 28 | $this->segments = $segments; |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Returns the long (original) part of this name. |
||
| 33 | * |
||
| 34 | * @return string |
||
| 35 | */ |
||
| 36 | public function long() |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Returns the shortened version of this name. |
||
| 43 | * |
||
| 44 | * @return string |
||
| 45 | */ |
||
| 46 | public function short() |
||
| 61 | } |