'ConfirmationAttributesExternal', ConfirmationType::REDIRECT => 'ConfirmationAttributesRedirect', ConfirmationType::EMBEDDED => 'ConfirmationAttributesEmbedded', ConfirmationType::QR => 'ConfirmationAttributesQr', ConfirmationType::MOBILE_APPLICATION => 'ConfirmationAttributesMobileApplication', ]; /** * @param string|null $type * @return AbstractConfirmationAttributes */ public function factory(?string $type = null): AbstractConfirmationAttributes { if (!is_string($type)) { throw new InvalidArgumentException('Invalid confirmation attributes value in confirmation factory'); } if (!array_key_exists($type, $this->typeClassMap)) { throw new InvalidArgumentException('Invalid confirmation attributes value type "' . $type . '"'); } $className = __NAMESPACE__ . '\\' . $this->typeClassMap[$type]; return new $className(); } /** * @param array $data * @param string|null $type * @return AbstractConfirmationAttributes */ public function factoryFromArray(array $data, ?string $type = null): AbstractConfirmationAttributes { if (null === $type) { if (array_key_exists('type', $data)) { $type = $data['type']; unset($data['type']); } else { throw new InvalidArgumentException( 'Parameter type not specified in ConfirmationAttributesFactory.factoryFromArray()' ); } } $confirmation = $this->factory($type); foreach ($data as $key => $value) { if ($confirmation->offsetExists($key)) { $confirmation->offsetSet($key, $value); } } return $confirmation; } }