![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/extmag/dhlshipping2/Helper/Response/ |
<?php /** * Copyright © Extmag. All rights reserved. */ namespace Extmag\DhlShipping\Helper\Response; use Extmag\Shiplab\Helper\Manager; use Extmag\Shiplab\Model\LogsFactory; use Exception; class Dhl { /** * @var string */ protected $carrier = 'dhl'; /** * @var string */ protected $requestType; /** * @var Manager */ protected $manager; /** * @param Manager $manager */ public function __construct(Manager $manager) { $this->manager = $manager; } /** * Parse * * @param $data * @param $context * @return array */ public function parse($data, $context) { try { $data = json_decode( json_encode( simplexml_load_string( mb_convert_encoding($data, "UTF-8"), 'SimpleXMLElement', LIBXML_NOCDATA ) ), true ); if (isset($data['Response']['Status']['ActionStatus'])) { $data = $this->parseFault($data['Response']['Status'], $context); } elseif (isset($data['GetQuoteResponse']['Note']['Condition'])) { $data = $this->parseFault($data['GetQuoteResponse']['Note'], $context); } else { $data = $this->parseSuccess($data, $context); } return $data; } catch (Exception $e) { $this->manager->warning($e->getMessage(), $e->getTrace()); return []; } } /** * Parse Fault * * @param array $data * @param $context * @return array */ protected function parseFault(array $data, $context) { $errors = []; if (!empty($data['Condition'])) { foreach ($this->get($data['Condition'] ?? []) as $error) { $errors[] = [ 'Code' => $error['ConditionCode'], 'Description' => $error['ConditionData'], ]; } } return [ 'Status' => '0', 'Carrier' => $this->carrier, 'Context' => $context, 'Type' => $this->requestType, 'Errors' => $errors, ]; } /** * Parse success response * * @param array $data * @param string $context * @return array */ protected function parseSuccess(array $data, string $context) { return []; } /** * Get * * @param $item * @return array */ protected function get($item) { if (!is_array($item) || !isset($item[0])) { if (!empty($item)) { $item = [$item]; } else { $item = []; } } return $item; } }