forked from christiankerl/WebServiceBundle
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathTypeRepository.php
More file actions
70 lines (56 loc) · 1.75 KB
/
TypeRepository.php
File metadata and controls
70 lines (56 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* This file is part of the BeSimpleSoapBundle.
*
* (c) Christian Kerl <christian-kerl@web.de>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace BeSimple\SoapBundle\Converter;
use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
use BeSimple\SoapBundle\Util\Assert;
use BeSimple\SoapBundle\Util\QName;
use BeSimple\SoapBundle\Util\Strings;
/**
* @author Christian Kerl <christian-kerl@web.de>
*/
class TypeRepository
{
const ARRAY_SUFFIX = '[]';
private $xmlNamespaces = array();
private $defaultTypeMap = array();
public function addXmlNamespace($prefix, $url)
{
$this->xmlNamespaces[$prefix] = $url;
}
public function getXmlNamespace($prefix)
{
return $this->xmlNamespaces[$prefix];
}
public function addDefaultTypeMapping($phpType, $xmlType)
{
Assert::thatArgumentNotNull('phpType', $phpType);
Assert::thatArgumentNotNull('xmlType', $xmlType);
$this->defaultTypeMap[$phpType] = $xmlType;
}
public function getXmlTypeMapping($phpType)
{
return isset($this->defaultTypeMap[$phpType]) ? $this->defaultTypeMap[$phpType] : null;
}
public function fixTypeInformation(ServiceDefinition $definition)
{
$typeMap = $this->defaultTypeMap;
foreach($definition->getAllTypes() as $type) {
$phpType = $type->getPhpType();
$xmlType = $type->getXmlType();
if (null === $phpType) {
throw new \InvalidArgumentException();
}
if (null === $xmlType) {
$xmlType = $this->getXmlTypeMapping($phpType);
}
$type->setXmlType($xmlType);
}
}
}