|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\AfterPay\Business\Api\Adapter\Converter; |
|
9
|
|
|
|
|
10
|
|
|
use ArrayObject; |
|
11
|
|
|
use Spryker\Shared\Kernel\Transfer\AbstractTransfer; |
|
12
|
|
|
use SprykerEco\Zed\AfterPay\Dependency\Service\AfterPayToUtilTextServiceInterface; |
|
13
|
|
|
|
|
14
|
|
|
class TransferToCamelCaseArrayConverter implements TransferToCamelCaseArrayConverterInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var \SprykerEco\Zed\AfterPay\Dependency\Service\AfterPayToUtilTextServiceInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $utilTextService; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param \SprykerEco\Zed\AfterPay\Dependency\Service\AfterPayToUtilTextServiceInterface $utilTextService |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(AfterPayToUtilTextServiceInterface $utilTextService) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->utilTextService = $utilTextService; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer $transfer |
|
31
|
|
|
* |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
|
|
public function convert(AbstractTransfer $transfer): array |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->convertTransferRecursively($transfer); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer $transfer |
|
41
|
|
|
* |
|
42
|
|
|
* @return array |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function convertTransferRecursively(AbstractTransfer $transfer): array |
|
45
|
|
|
{ |
|
46
|
|
|
$originalArray = $transfer->toArray(false); |
|
47
|
|
|
$camelCaseArray = []; |
|
48
|
|
|
|
|
49
|
|
|
foreach ($originalArray as $key => $value) { |
|
50
|
|
|
$camelCaseKey = $this->underscoreToCamelCase($key); |
|
51
|
|
|
|
|
52
|
|
|
if ($value instanceof AbstractTransfer) { |
|
53
|
|
|
$camelCaseArray[$camelCaseKey] = $this->convertTransferRecursively($value); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if ($value instanceof ArrayObject) { |
|
57
|
|
|
$camelCaseArray[$camelCaseKey] = []; |
|
58
|
|
|
foreach ($value as $valueItem) { |
|
59
|
|
|
$camelCaseArray[$camelCaseKey][] = $this->convertTransferRecursively($valueItem); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if (is_scalar($value)) { |
|
64
|
|
|
$camelCaseArray[$camelCaseKey] = $value; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $camelCaseArray; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param string $string |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function underscoreToCamelCase(string $string): string |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->utilTextService->separatorToCamelCase($string, '_'); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|