-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOrchestrator.php
64 lines (55 loc) · 2.16 KB
/
Orchestrator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace Denal05\SwiftOtterOrderExport;
use Denal05\SwiftOtterOrderExport\Action\PushDetailsToWebservice;
use Denal05\SwiftOtterOrderExport\Action\TransformOrderToArray;
use Denal05\SwiftOtterOrderExport\Model\HeaderData;
use Magento\Framework\Exception\NoSuchEntityException;
//use Magento\Webapi\Controller\Rest\RequestValidator;
use Psr\Log\LoggerInterface;
class Orchestrator
{
private TransformOrderToArray $orderToArray;
//private RequestValidator $requestValidator;
private PushDetailsToWebservice $pushDetailsToWebservice;
private LoggerInterface $logger;
public function __construct(
TransformOrderToArray $orderToArray,
//RequestValidator $requestValidator,
PushDetailsToWebservice $pushDetailsToWebservice,
LoggerInterface $logger
) {
$this->orderToArray = $orderToArray;
//$this->requestValidator = $requestValidator;
$this->pushDetailsToWebservice = $pushDetailsToWebservice;
$this->logger = $logger;
}
public function run(
int $orderId,
HeaderData $headerData
): array {
// throw new NoSuchEntityException(__('There was an error: no such entity'));
$results = [
'success' => false,
'error' => null
];
// if (!$this->requestValidator->isValid($orderId)) {
// $results['error'] = (string) __('The order ID provided was invalid.');
// return $results;
// }
$orderDetails = $this->orderToArray->execute($orderId, $headerData);
try {
$this->pushDetailsToWebservice->execute($orderId, $orderDetails);
} catch (NoSuchEntityException $exception) {
$results['error'] = (string) $exception->getMessage(); // NoSuchEntityException
$results['success'] = false;
} catch (\Exception $exception) {
$this->logger->error($exception->getMessage(), [
'trace' => $exception->getTraceAsString()
]);
$results['error'] = (string) $exception->getMessage(); // general Exception
$results['success'] = false;
}
return $results;
}
}