forked from BeSimple/BeSimpleSoapBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebServiceContext.php
More file actions
135 lines (106 loc) · 4.59 KB
/
WebServiceContext.php
File metadata and controls
135 lines (106 loc) · 4.59 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?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;
use BeSimple\SoapBundle\Converter\TypeRepository;
use BeSimple\SoapBundle\ServiceBinding\MessageBinderInterface;
use BeSimple\SoapBundle\ServiceBinding\ServiceBinder;
use BeSimple\SoapBundle\ServiceDefinition\Dumper\DumperInterface;
use BeSimple\SoapCommon\Classmap;
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
use BeSimple\SoapServer\SoapServerBuilder;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Loader\LoaderInterface;
/**
* WebServiceContext.
*
* @author Christian Kerl <christian-kerl@web.de>
*/
class WebServiceContext
{
private $classmap;
private $typeRepository;
private $converterRepository;
private $wsdlFileDumper;
private $options;
private $serviceDefinition;
private $serviceBinder;
private $serverBuilder;
public function __construct(LoaderInterface $loader, DumperInterface $dumper, Classmap $classmap, TypeRepository $typeRepository, TypeConverterCollection $converters, array $options)
{
$this->loader = $loader;
$this->wsdlFileDumper = $dumper;
$this->classmap = $classmap;
$this->typeRepository = $typeRepository;
$this->converters = $converters;
$this->options = $options;
}
public function getServiceDefinition()
{
if (null === $this->serviceDefinition) {
$cacheDefinition = new ConfigCache(sprintf('%s/%s.definition.php', $this->options['cache_dir'], $this->options['name']), $this->options['debug']);
if ($cacheDefinition->isFresh()) {
$this->serviceDefinition = include (string) $cacheDefinition;
} else {
if (!$this->loader->supports($this->options['resource'], $this->options['resource_type'])) {
throw new \LogicException(sprintf('Cannot load "%s" (%s)', $this->options['resource'], $this->options['resource_type']));
}
$this->serviceDefinition = $this->loader->load($this->options['resource'], $this->options['resource_type']);
$this->serviceDefinition->setName($this->options['name']);
$this->serviceDefinition->setNamespace($this->options['namespace']);
$this->serviceDefinition->setClassmap($this->classmap);
$this->classmap = null;
$this->typeRepository->fixTypeInformation($this->serviceDefinition);
}
}
return $this->serviceDefinition;
}
public function getWsdlFileContent($endpoint = null)
{
return file_get_contents($this->getWsdlFile($endpoint));
}
public function getWsdlFile($endpoint = null)
{
$file = sprintf('%s/%s.%s.wsdl', $this->options['cache_dir'], $this->options['name'], md5($endpoint));
$cacheWsdl = new ConfigCache($file, $this->options['debug']);
if(!$cacheWsdl->isFresh()) {
$serviceDefinition = $this->getServiceDefinition();
$cacheWsdl->write($this->wsdlFileDumper->dumpServiceDefinition($serviceDefinition, $endpoint));
$cacheDefinition = new ConfigCache(sprintf('%s/%s.definition.php', $this->options['cache_dir'], $this->options['name']), $this->options['debug']);
$cacheDefinition->write('<?php return unserialize('.var_export(serialize($serviceDefinition), true).');');
}
return (string) $cacheWsdl;
}
public function getServiceBinder()
{
if (null === $this->serviceBinder) {
$this->serviceBinder = new ServiceBinder(
$this->getServiceDefinition(),
new $this->options['binder_request_header_class'](),
new $this->options['binder_request_class'](),
new $this->options['binder_response_class']()
);
}
return $this->serviceBinder;
}
public function getServerBuilder()
{
if (null === $this->serverBuilder) {
$this->serverBuilder = SoapServerBuilder::createWithDefaults()
->withWsdl($this->getWsdlFile())
->withClassmap($this->getServiceDefinition()->getClassmap())
->withTypeConverters($this->converters)
;
if (null !== $this->options['cache_type']) {
$this->serverBuilder->withWsdlCache($this->options['cache_type']);
}
}
return $this->serverBuilder;
}
}