|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of gpupo/netshoes-sdk |
|
5
|
|
|
* Created by Gilmar Pupo <[email protected]> |
|
6
|
|
|
* For the information of copyright and license you should read the file |
|
7
|
|
|
* LICENSE which is distributed with this source code. |
|
8
|
|
|
* Para a informação dos direitos autorais e de licença você deve ler o arquivo |
|
9
|
|
|
* LICENSE que é distribuído com este código-fonte. |
|
10
|
|
|
* Para obtener la información de los derechos de autor y la licencia debe leer |
|
11
|
|
|
* el archivo LICENSE que se distribuye con el código fuente. |
|
12
|
|
|
* For more information, see <http://www.g1mr.com/>. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Gpupo\NetshoesSdk\Entity\Order\Decorator; |
|
16
|
|
|
|
|
17
|
|
|
use Gpupo\Common\Entity\Collection; |
|
18
|
|
|
use Gpupo\CommonSdk\Traits\LoggerTrait; |
|
19
|
|
|
use Gpupo\NetshoesSdk\Entity\Order\Order; |
|
20
|
|
|
|
|
21
|
|
|
abstract class AbstractDecorator extends Collection |
|
22
|
|
|
{ |
|
23
|
|
|
use LoggerTrait; |
|
24
|
|
|
|
|
25
|
|
|
protected $name = ''; |
|
26
|
|
|
|
|
27
|
5 |
|
protected function fail($string = '') |
|
28
|
|
|
{ |
|
29
|
5 |
|
$message = 'Order incomplete for status ['.$string.']'; |
|
30
|
5 |
|
$this->log('error', $message, [ |
|
31
|
5 |
|
'order' => $this->getOrder(), |
|
32
|
|
|
]); |
|
33
|
|
|
|
|
34
|
5 |
|
throw new \InvalidArgumentException($message); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
5 |
|
protected function invalid($string = '') |
|
38
|
|
|
{ |
|
39
|
5 |
|
$message = 'Attribute invalid: '.$string.' '; |
|
40
|
|
|
|
|
41
|
5 |
|
throw new \InvalidArgumentException($message); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
10 |
|
public function setOrder(Order $order) |
|
45
|
|
|
{ |
|
46
|
10 |
|
$this->set('order', $order); |
|
47
|
10 |
|
$this->initLogger($order->getLogger()); |
|
48
|
|
|
|
|
49
|
10 |
|
return $this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
5 |
|
public function getOrder() |
|
53
|
|
|
{ |
|
54
|
5 |
|
return $this->get('order'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
14 |
|
public function validate() |
|
58
|
|
|
{ |
|
59
|
14 |
|
$order = $this->getOrder(); |
|
60
|
|
|
|
|
61
|
14 |
|
if (empty($order)) { |
|
62
|
4 |
|
$this->invalid('Order'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
10 |
|
$this->getOrder()->check(); |
|
66
|
|
|
|
|
67
|
10 |
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
15 |
|
public function toArray() |
|
71
|
|
|
{ |
|
72
|
|
|
try { |
|
73
|
15 |
|
$this->validate(); |
|
74
|
10 |
|
$array = $this->factoryArray(); |
|
|
|
|
|
|
75
|
5 |
|
} catch (\Exception $e) { |
|
76
|
5 |
|
$this->fail($this->name . ' ('.$e->getMessage().')'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
10 |
|
return $array; |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: