public function resolveResponseContentType(XmlDeserializationVisitor $visitor, $data, array $type, Context $context)
 {
     $operation = $visitor->getCurrentObject()->getHead()->getOperation();
     switch ($operation) {
         case OperationType::OPERATION_PAYMENT_INIT:
             $type['name'] = 'PHPCommerce\\Vendor\\RatePAY\\Service\\Payment\\Type\\Response\\PaymentInitResponseType';
             return $context->accept($data, $type);
             break;
         case OperationType::OPERATION_PAYMENT_REQUEST:
             $type['name'] = 'PHPCommerce\\Vendor\\RatePAY\\Service\\Payment\\Type\\Response\\PaymentRequestResponseType';
             return $context->accept($data, $type);
             break;
         case OperationType::OPERATION_PAYMENT_CONFIRM:
             $type['name'] = 'PHPCommerce\\Vendor\\RatePAY\\Service\\Payment\\Type\\Response\\PaymentConfirmResponseType';
             return $context->accept($data, $type);
             break;
         case OperationType::OPERATION_PAYMENT_CHANGE:
             $type['name'] = 'PHPCommerce\\Vendor\\RatePAY\\Service\\Payment\\Type\\Response\\PaymentChangeResponseType';
             return $context->accept($data, $type);
             break;
         case OperationType::OPERATION_CONFIRMATION_DELIVER:
             $type['name'] = 'PHPCommerce\\Vendor\\RatePAY\\Service\\Payment\\Type\\Response\\ConfirmationDeliverResponseType';
             return $context->accept($data, $type);
             break;
         case OperationType::OPERATION_CONFIGURATION_REQUEST:
             $type['name'] = 'PHPCommerce\\Vendor\\RatePAY\\Service\\Payment\\Type\\Response\\ConfigurationResponseType';
             return $context->accept($data, $type);
             break;
         default:
             throw new RuntimeException("Unknown Operation: " . $operation);
             break;
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function getServiceConfig()
 {
     return array('aliases' => array('jms_serializer.metadata_driver' => 'jms_serializer.metadata.chain_driver', 'jms_serializer.object_constructor' => 'jms_serializer.unserialize_object_constructor'), 'factories' => array('jms_serializer.handler_registry' => new HandlerRegistryFactory(), 'jms_serializer.datetime_handler' => function (ServiceManager $sm) {
         $options = $sm->get('Configuration');
         $options = new Handlers($options['jms_serializer']['handlers']);
         $dateTimeOptions = $options->getDatetime();
         return new DateHandler($dateTimeOptions['default_format'], $dateTimeOptions['default_timezone']);
     }, 'jms_serializer.event_dispatcher' => new EventDispatcherFactory(), 'jms_serializer.metadata.cache' => new MetadataCacheFactory(), 'jms_serializer.metadata.yaml_driver' => new MetadataDriverFactory('JMS\\Serializer\\Metadata\\Driver\\YamlDriver'), 'jms_serializer.metadata.xml_driver' => new MetadataDriverFactory('JMS\\Serializer\\Metadata\\Driver\\XmlDriver'), 'jms_serializer.metadata.php_driver' => new MetadataDriverFactory('JMS\\Serializer\\Metadata\\Driver\\PhpDriver'), 'jms_serializer.metadata.file_locator' => function (ServiceManager $sm) {
         $options = $sm->get('Configuration');
         $options = new Metadata($options['jms_serializer']['metadata']);
         $directories = array();
         foreach ($options->getDirectories() as $directory) {
             if (!isset($directory['path'], $directory['namespace_prefix'])) {
                 throw new \RuntimeException(sprintf('The directory must have the attributes "path" and "namespace_prefix, "%s" given.', implode(', ', array_keys($directory))));
             }
             $directories[rtrim($directory['namespace_prefix'], '\\')] = rtrim($directory['path'], '\\/');
         }
         return new FileLocator($directories);
     }, 'jms_serializer.metadata.annotation_driver' => function (ServiceManager $sm) {
         $options = $sm->get('Configuration');
         $options = new Metadata($options['jms_serializer']['metadata']);
         $reader = new AnnotationReader();
         $reader = new CachedReader(new IndexedReader($reader), $sm->get($options->getAnnotationCache()));
         return new AnnotationDriver($reader);
     }, 'jms_serializer.metadata.chain_driver' => function (ServiceManager $sm) {
         $annotationDriver = $sm->get('jms_serializer.metadata.annotation_driver');
         $phpDriver = $sm->get('jms_serializer.metadata.php_driver');
         $xmlDriver = $sm->get('jms_serializer.metadata.xml_driver');
         $yamlDriver = $sm->get('jms_serializer.metadata.yaml_driver');
         return new DriverChain(array($yamlDriver, $xmlDriver, $phpDriver, $annotationDriver));
     }, 'jms_serializer.metadata.lazy_loading_driver' => function (ServiceManager $sm) {
         return new LazyLoadingDriver($sm, 'jms_serializer.metadata_driver');
     }, 'jms_serializer.metadata_factory' => function (ServiceManager $sm) {
         $options = $sm->get('Configuration');
         $options = new Metadata($options['jms_serializer']['metadata']);
         $lazyLoadingDriver = $sm->get('jms_serializer.metadata.lazy_loading_driver');
         return new MetadataFactory($lazyLoadingDriver, 'Metadata\\ClassHierarchyMetadata', $options->getDebug());
     }, 'jms_serializer.camel_case_naming_strategy' => function (ServiceManager $sm) {
         $options = $sm->get('Configuration');
         $options = new PropertyNaming($options['jms_serializer']['property_naming']);
         return new CamelCaseNamingStrategy($options->getSeparator(), $options->getLowercase());
     }, 'jms_serializer.identical_naming_strategy' => function (ServiceManager $sm) {
         return new IdenticalPropertyNamingStrategy();
     }, 'jms_serializer.serialized_name_annotation_strategy' => function (ServiceManager $sm) {
         $options = $sm->get('Configuration');
         if (isset($options['jms_serializer']['naming_strategy'])) {
             if ($options['jms_serializer']['naming_strategy'] == 'identical') {
                 return new SerializedNameAnnotationStrategy($sm->get('jms_serializer.identical_naming_strategy'));
             }
         }
         return new SerializedNameAnnotationStrategy($sm->get('jms_serializer.camel_case_naming_strategy'));
     }, 'jms_serializer.naming_strategy' => 'JMSSerializerModule\\Service\\NamingStrategyFactory', 'jms_serializer.json_serialization_visitor' => function (ServiceManager $sm) {
         $options = $sm->get('Configuration');
         $options = new Visitors($options['jms_serializer']['visitors']);
         $jsonOptions = $options->getJson();
         $vistor = new JsonSerializationVisitor($sm->get('jms_serializer.naming_strategy'));
         $vistor->setOptions($jsonOptions['options']);
         return $vistor;
     }, 'jms_serializer.json_deserialization_visitor' => function (ServiceManager $sm) {
         return new JsonDeserializationVisitor($sm->get('jms_serializer.naming_strategy'), $sm->get('jms_serializer.object_constructor'));
     }, 'jms_serializer.xml_serialization_visitor' => function (ServiceManager $sm) {
         return new XmlSerializationVisitor($sm->get('jms_serializer.naming_strategy'));
     }, 'jms_serializer.xml_deserialization_visitor' => function (ServiceManager $sm) {
         $options = $sm->get('Configuration');
         $options = new Visitors($options['jms_serializer']['visitors']);
         $xmlOptions = $options->getXml();
         $visitor = new XmlDeserializationVisitor($sm->get('jms_serializer.naming_strategy'), $sm->get('jms_serializer.object_constructor'));
         $visitor->setDoctypeWhitelist($xmlOptions['doctype_whitelist']);
         return $visitor;
     }, 'jms_serializer.yaml_serialization_visitor' => function (ServiceManager $sm) {
         return new YamlSerializationVisitor($sm->get('jms_serializer.naming_strategy'));
     }, 'jms_serializer.serializer' => 'JMSSerializerModule\\Service\\SerializerFactory'), 'invokables' => array('jms_serializer.unserialize_object_constructor' => 'JMS\\Serializer\\Construction\\UnserializeObjectConstructor', 'jms_serializer.array_collection_handler' => 'JMS\\Serializer\\Handler\\ArrayCollectionHandler', 'jms_serializer.doctrine_proxy_subscriber' => 'JMS\\Serializer\\EventDispatcher\\Subscriber\\DoctrineProxySubscriber'));
 }
Ejemplo n.º 3
0
 public function deserializeAnyType(XmlDeserializationVisitor $visitor, $data, array $type)
 {
     return $visitor->visitNull($data, $type, $context);
 }
 /**
  * @param mixed   $data
  * @param array   $type
  * @param Context $context
  * @return float|mixed
  */
 public function visitDouble($data, array $type, Context $context)
 {
     return parent::visitDouble((double) str_replace(',', '.', (string) $data), $type, $context);
 }
 /**
  * Create wrapper from decoded xml
  *
  * @param XmlDeserializationVisitor $visitor
  * @param mixed                     $data
  * @param array                     $type
  * @param Context                   $context
  *
  * @return EventContainer
  * @throws RuntimeException
  */
 public function deserializeContainerXml(XmlDeserializationVisitor $visitor, $data, array $type, Context $context)
 {
     if (!is_object($data)) {
         throw new RuntimeException(sprintf('Deserialized SimpleXMLElement data expected, got "%s"', gettype($data)));
     }
     if (!$data instanceof \SimpleXMLElement) {
         throw new RuntimeException(sprintf('Deserialized SimpleXMLElement data expected, got "%s"', get_class($data)));
     }
     if (!isset($data->data) || !$data->data instanceof \SimpleXMLElement) {
         throw new RuntimeException(sprintf('Deserialized data child node "event" missed'));
     }
     if (!isset($data['type'])) {
         throw new RuntimeException(sprintf('Deserialized "type" attribute for d"event" node missed'));
     }
     $container = $this->createEventContainer();
     $visitor->startVisitingObject($context->getMetadataFactory()->getMetadataForClass(get_class($container)), $container, [], $context);
     $event = $visitor->getNavigator()->accept($data->data, array('name' => $this->namingStrategy->typeToClass((string) $data['type'])), $context);
     $this->setContainerEvent($container, $event);
     return $container;
 }
Ejemplo n.º 6
0
<?php

include './vendor/autoload.php';
use Doctrine\Common\Annotations\AnnotationRegistry;
use GuzzleHttp\Client;
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
use JMS\Serializer\Naming\SerializedNameAnnotationStrategy;
use JMS\Serializer\SerializerBuilder;
use JMS\Serializer\XmlDeserializationVisitor;
AnnotationRegistry::registerLoader('class_exists');
/**
 * START: Prepare Serializer
 */
$xmlVisitor = new XmlDeserializationVisitor(new SerializedNameAnnotationStrategy(new IdenticalPropertyNamingStrategy()));
$xmlVisitor->setDoctypeWhitelist(['<!DOCTYPE XGResponse SYSTEM "http://intcom.xml.techdata-europe.com:8080/XMLGate/XMLGateResponse.dtd">']);
$serializer = \JMS\Serializer\SerializerBuilder::create()->addDefaultSerializationVisitors()->setDeserializationVisitor('tech_data', $xmlVisitor)->build();
/**
 * STOP
 */
/**
 * START: Create Tech Data models
 */
$orderEnv = new \Whisller\TechData\Components\OrderEnv('my-auth-code', 1);
$deliver = new \Whisller\TechData\Components\DeliverTo();
$address = new \Whisller\TechData\Components\Address('69, Flat X', 'Nice Street', 'Nibylandia', 'UK');
$deliver->setAddress($address);
$head = new \Whisller\TechData\Components\Head('my title', new DateTime('now', new DateTimeZone('Europe/London')), $deliver);
$line = new \Whisller\TechData\Components\Line(1, 123, 55, [new \Whisller\TechData\Components\AddItemID('EAN', 'my-ean')]);
$body = new \Whisller\TechData\Components\Body($line);
$order = new \Whisller\TechData\Components\Order('GBP', $head, $body);
$orderEnv->addOrder($order);