@@ 20-51 (lines=32) @@ | ||
17 | * |
|
18 | * @package Nnx\JmsSerializerModule\Visitor |
|
19 | */ |
|
20 | class JsonSerializationVisitorFactory implements FactoryInterface, MutableCreationOptionsInterface |
|
21 | { |
|
22 | use MutableCreationOptionsTrait, NamingStrategyTrait; |
|
23 | ||
24 | /** |
|
25 | * @param ServiceLocatorInterface $serviceLocator |
|
26 | * |
|
27 | * @return FileLocator |
|
28 | * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
|
29 | * @throws \Nnx\JmsSerializerModule\Visitor\Exception\RuntimeException |
|
30 | * @throws \Nnx\JmsSerializerModule\MetadataDriver\Exception\RuntimeException |
|
31 | */ |
|
32 | public function createService(ServiceLocatorInterface $serviceLocator) |
|
33 | { |
|
34 | $namingStrategy = $this->getNamingStrategyFromContainer($serviceLocator); |
|
35 | $visitor = new JsonSerializationVisitor($namingStrategy); |
|
36 | ||
37 | $creationOptions = $this->getCreationOptions(); |
|
38 | if (array_key_exists('jsonOptions', $creationOptions)) { |
|
39 | $jsonOptions = $creationOptions['jsonOptions']; |
|
40 | if (!is_array($jsonOptions)) { |
|
41 | $errMsg = 'Json options is not array'; |
|
42 | throw new Exception\RuntimeException($errMsg); |
|
43 | } |
|
44 | if (array_key_exists('options', $jsonOptions)) { |
|
45 | $visitor->setOptions($jsonOptions['options']); |
|
46 | } |
|
47 | } |
|
48 | ||
49 | return $visitor; |
|
50 | } |
|
51 | } |
|
52 |
@@ 19-48 (lines=30) @@ | ||
16 | * |
|
17 | * @package Nnx\JmsSerializerModule\Visitor |
|
18 | */ |
|
19 | class XmlDeserializationVisitorFactory implements FactoryInterface, MutableCreationOptionsInterface |
|
20 | { |
|
21 | use MutableCreationOptionsTrait, NamingStrategyTrait; |
|
22 | ||
23 | /** |
|
24 | * @param ServiceLocatorInterface $serviceLocator |
|
25 | * |
|
26 | * @return XmlDeserializationVisitor |
|
27 | * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
|
28 | * @throws \Nnx\JmsSerializerModule\Visitor\Exception\RuntimeException |
|
29 | */ |
|
30 | public function createService(ServiceLocatorInterface $serviceLocator) |
|
31 | { |
|
32 | $creationOptions = $this->getCreationOptions(); |
|
33 | ||
34 | $namingStrategy = $this->getNamingStrategyFromContainer($serviceLocator); |
|
35 | $xmlDeserializationVisitor = new XmlDeserializationVisitor($namingStrategy); |
|
36 | ||
37 | if (array_key_exists('doctypeWhitelist', $creationOptions)) { |
|
38 | $doctypeWhitelist = $creationOptions['doctypeWhitelist']; |
|
39 | if (!is_array($doctypeWhitelist)) { |
|
40 | $errMsg = 'Doctype whitelist not array'; |
|
41 | throw new Exception\RuntimeException($errMsg); |
|
42 | } |
|
43 | $xmlDeserializationVisitor->setDoctypeWhitelist($doctypeWhitelist); |
|
44 | } |
|
45 | ||
46 | return $xmlDeserializationVisitor; |
|
47 | } |
|
48 | } |
|
49 |