1 <?php
2 3 4
5 namespace Team3\PayU\Order\Transformer\UserOrder\Strategy;
6
7 use Team3\PayU\Order\Model\Buyer\BuyerInterface;
8 use Team3\PayU\Order\Model\OrderInterface;
9 use Team3\PayU\Order\Transformer\UserOrder\TransformerProperties;
10 use Team3\PayU\Order\Transformer\UserOrder\TransformerPropertiesRegExp;
11 use Team3\PayU\PropertyExtractor\ExtractorResult;
12
13 class BuyerTransformer implements UserOrderTransformerStrategyInterface
14 {
15 16 17
18 public function transform(
19 OrderInterface $order,
20 ExtractorResult $extractorResult
21 ) {
22 $this->copyValue(
23 $order->getBuyer(),
24 $extractorResult
25 );
26 }
27
28 29 30
31 public function supports($propertyName)
32 {
33 return 1 === preg_match(
34 TransformerPropertiesRegExp::BUYER_REGEXP,
35 $propertyName
36 );
37 }
38
39 40 41 42
43 private function copyValue(
44 BuyerInterface $buyer,
45 ExtractorResult $extractorResult
46 ) {
47 switch ($extractorResult->getPropertyName()) {
48 case TransformerProperties::BUYER_EMAIL:
49 $buyer->setEmail($extractorResult->getValue());
50 break;
51 case TransformerProperties::BUYER_PHONE:
52 $buyer->setPhone($extractorResult->getValue());
53 break;
54 case TransformerProperties::BUYER_FIRST_NAME:
55 $buyer->setFirstName($extractorResult->getValue());
56 break;
57 case TransformerProperties::BUYER_LAST_NAME:
58 $buyer->setLastName($extractorResult->getValue());
59 break;
60 default:
61 }
62 }
63 }
64