objectManager = $objectManager; $this->amazonName = $amazonName; $this->perCountryNameHandlers = $perCountryNameHandlers; } /** * @param array $data * @return AmazonName * @throws LocalizedException */ public function create(array $data = []) { $nameParts = explode(' ', trim($data['name']), 2); $data[AmazonNameInterface::FIRST_NAME] = $nameParts[0]; $data[AmazonNameInterface::LAST_NAME] = $nameParts[1] ?? '.'; $amazonName = $this->objectManager->create(AmazonName::class, ['data' => $data]); $countryCode = strtoupper($data['country']); if (empty($this->nameDecoratorPool[$countryCode])) { return $amazonName; } $amazonName = $this->objectManager->create( $this->nameDecoratorPool[$countryCode], [ 'amazonName' => $amazonName, ] ); if (!$amazonName instanceof AmazonNameInterface) { throw new LocalizedException( __( 'Address country handler %1 must be of type %2', [$this->nameDecoratorPool[$countryCode], AmazonName::class] ) ); } return $amazonName; } }