1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of RussianPost SDK package. |
5
|
|
|
* |
6
|
|
|
* © Appwilio (http://appwilio.com), greabock (https://github.com/greabock), JhaoDa (https://github.com/jhaoda) |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Appwilio\RussianPostSDK\Dispatching\Endpoints\Orders\Entites; |
15
|
|
|
|
16
|
|
|
use Appwilio\RussianPostSDK\Dispatching\DataAware; |
17
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Instantiator; |
18
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Contracts\Arrayable; |
19
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Endpoints\Services\Entities\NormalizedFio; |
20
|
|
|
|
21
|
|
|
class Recipient implements Arrayable |
22
|
|
|
{ |
23
|
|
|
use DataAware; |
24
|
|
|
|
25
|
|
|
public static function fromNormalizedFio(NormalizedFio $normalizedFio) |
26
|
|
|
{ |
27
|
|
|
$data = [ |
28
|
|
|
'surname' => $normalizedFio->getLastName(), |
29
|
|
|
'given-name' => $normalizedFio->getFirstName(), |
30
|
|
|
'middle-name' => $normalizedFio->getMiddleName(), |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
$raw = \trim(\implode(' ', $data)); |
34
|
|
|
|
35
|
|
|
if ($raw) { |
36
|
|
|
$data['recipient-name'] = $raw; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return Instantiator::instantiate(self::class, $data); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function __construct(string $rawName) |
43
|
|
|
{ |
44
|
|
|
$this->data['recipient-name'] = $rawName; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function setFirstName(string $firstName) |
48
|
|
|
{ |
49
|
|
|
$this->data['given-name'] = $firstName; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function setMiddleName(string $middleName) |
53
|
|
|
{ |
54
|
|
|
$this->data['middle-name'] = $middleName; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function setLastName(string $lastName) |
58
|
|
|
{ |
59
|
|
|
$this->data['surname'] = $lastName; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function setPhoneNumber(string $phoneNumber) |
63
|
|
|
{ |
64
|
|
|
$this->data['tel-address'] = $phoneNumber; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|