/** * {@inheritdoc} */ public static function fromCommand(OperationCommand $command) { $uriSegments = $command->getRequest()->getUrl(true)->getPathSegments(); $referencingCaseUuId = end($uriSegments); if (!is_string($referencingCaseUuId) || 36 != strlen($referencingCaseUuId)) { $referencingCaseUuId = null; } $data = $command->getResponse()->json(); $address = isset($data['address']) ? self::hydrateModelProperties(new Address(), $data['address']) : null; $prospectiveLandlordAddress = isset($data['prospectiveLandlord']['address']) ? self::hydrateModelProperties(new Address(), $data['prospectiveLandlord']['address']) : null; $prospectiveLandlord = isset($data['prospectiveLandlord']) ? self::hydrateModelProperties(new ProspectiveLandlord(), $data['prospectiveLandlord'], array(), array('address' => $prospectiveLandlordAddress)) : null; $applications = array(); if (isset($data['applications']) && is_array($data['applications'])) { foreach ($data['applications'] as $key => $object) { $application = ReferencingApplication::hydrate($object); $applications[$key] = $application; } } return self::hydrateModelProperties(new self(), $data, array('caseId' => 'referencingCaseUuId', 'tenancyTerm' => 'tenancyTermInMonths'), array('caseId' => $referencingCaseUuId, 'address' => $address, 'prospectiveLandlord' => $prospectiveLandlord, 'applications' => $applications)); }