@@ 19-73 (lines=55) @@ | ||
16 | /** |
|
17 | * Class Array2ObjectBuilder |
|
18 | */ |
|
19 | class Array2ObjectBuilder extends AbstractBuilder |
|
20 | { |
|
21 | /** |
|
22 | * @var PropertyWriterInterface |
|
23 | */ |
|
24 | private $writer; |
|
25 | ||
26 | /** |
|
27 | * @return PropertyWriterInterface |
|
28 | */ |
|
29 | public function getWriter() |
|
30 | { |
|
31 | return $this->writer; |
|
32 | } |
|
33 | ||
34 | /** |
|
35 | * @param PropertyWriterInterface $writer |
|
36 | * |
|
37 | * @return $this |
|
38 | */ |
|
39 | public function setWriter($writer) |
|
40 | { |
|
41 | $this->writer = $writer; |
|
42 | ||
43 | return $this; |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * Build custom Array2Object instance |
|
48 | */ |
|
49 | public function build() |
|
50 | { |
|
51 | if ($this->getContext()) { |
|
52 | $context = $this->getContext(); |
|
53 | } else { |
|
54 | $context = new Array2ObjectContext(); |
|
55 | } |
|
56 | ||
57 | $this->prepareContext($context); |
|
58 | ||
59 | return new Array2Object($context); |
|
60 | } |
|
61 | ||
62 | /** |
|
63 | * @inheritDoc |
|
64 | */ |
|
65 | protected function prepareContext(AbstractContext $context) |
|
66 | { |
|
67 | parent::prepareContext($context); |
|
68 | ||
69 | if ($context instanceof Array2ObjectContext) { |
|
70 | $context->setWriter($this->getWriter() ?: new AccessorWriter()); |
|
71 | } |
|
72 | } |
|
73 | } |
@@ 15-69 (lines=55) @@ | ||
12 | use Rafrsr\LibArray2Object\Reader\AccessorReader; |
|
13 | use Rafrsr\LibArray2Object\Reader\PropertyReaderInterface; |
|
14 | ||
15 | class Object2ArrayBuilder extends AbstractBuilder |
|
16 | { |
|
17 | /** |
|
18 | * @var PropertyReaderInterface |
|
19 | */ |
|
20 | private $reader; |
|
21 | ||
22 | /** |
|
23 | * @return PropertyReaderInterface |
|
24 | */ |
|
25 | public function getReader() |
|
26 | { |
|
27 | return $this->reader; |
|
28 | } |
|
29 | ||
30 | /** |
|
31 | * @param PropertyReaderInterface $reader |
|
32 | * |
|
33 | * @return $this |
|
34 | */ |
|
35 | public function setReader($reader) |
|
36 | { |
|
37 | $this->reader = $reader; |
|
38 | ||
39 | return $this; |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * Build custom Array2Object instance |
|
44 | */ |
|
45 | public function build() |
|
46 | { |
|
47 | if ($this->getContext()) { |
|
48 | $context = $this->getContext(); |
|
49 | } else { |
|
50 | $context = new Object2ArrayContext(); |
|
51 | } |
|
52 | ||
53 | $this->prepareContext($context); |
|
54 | ||
55 | return new Object2Array($context); |
|
56 | } |
|
57 | ||
58 | /** |
|
59 | * @inheritDoc |
|
60 | */ |
|
61 | protected function prepareContext(AbstractContext $context) |
|
62 | { |
|
63 | parent::prepareContext($context); |
|
64 | ||
65 | if ($context instanceof Object2ArrayContext) { |
|
66 | $context->setReader($this->getReader() ?: new AccessorReader()); |
|
67 | } |
|
68 | } |
|
69 | } |