|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the prooph/cargo-sample2. |
|
4
|
|
|
* (c) Alexander Miertsch <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* Date: 06.12.2015 - 11:23 PM |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace Codeliner\CargoBackend\Http\Action; |
|
12
|
|
|
|
|
13
|
|
|
use Codeliner\CargoBackend\Application\Booking\BookingService; |
|
14
|
|
|
use Codeliner\CargoBackend\Application\Booking\Dto\RouteCandidateDto; |
|
15
|
|
|
use Codeliner\CargoBackend\Model\Cargo\TrackingId; |
|
16
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
17
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
18
|
|
|
use Zend\Diactoros\Response\EmptyResponse; |
|
19
|
|
|
use Zend\Diactoros\Response\JsonResponse; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class GetRouteCandidates |
|
23
|
|
|
* |
|
24
|
|
|
* @package Codeliner\CargoBackend\Application\Action |
|
25
|
|
|
*/ |
|
26
|
|
|
final class GetRouteCandidates |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var BookingService |
|
30
|
|
|
*/ |
|
31
|
|
|
private $bookingService; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* GetRouteCandidates constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param BookingService $bookingService |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(BookingService $bookingService) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->bookingService = $bookingService; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
if (null === $trackingId = $request->getAttribute('trackingId')) { |
|
46
|
|
|
return new EmptyResponse(404); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$candidateIndex = 1; |
|
50
|
|
|
return new JsonResponse([ |
|
51
|
|
|
'routeCandidates' => array_map(function(RouteCandidateDto $routeCandidate) use (&$candidateIndex) { |
|
52
|
|
|
$candidateData = $routeCandidate->getArrayCopy(); |
|
53
|
|
|
$candidateData['id'] = $candidateIndex; |
|
54
|
|
|
$candidateIndex++; |
|
55
|
|
|
return $candidateData; |
|
56
|
|
|
}, $this->bookingService->requestPossibleRoutesForCargo($trackingId)) |
|
57
|
|
|
]); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.