-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathWebServiceContext.php
116 lines (91 loc) · 3.71 KB
/
WebServiceContext.php
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
<?php
/*
* This file is part of the WebServiceBundle.
*
* (c) Christian Kerl <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Bundle\WebServiceBundle;
use Bundle\WebServiceBundle\Converter\TypeRepository;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Loader\LoaderInterface;
use Bundle\WebServiceBundle\Converter\ConverterRepository;
use Bundle\WebServiceBundle\ServiceBinding\ServiceBinder;
use Bundle\WebServiceBundle\ServiceBinding\MessageBinderInterface;
use Bundle\WebServiceBundle\ServiceDefinition\Dumper\DumperInterface;
use Bundle\WebServiceBundle\Soap\SoapServerFactory;
/**
* WebServiceContext.
*
* @author Christian Kerl <[email protected]>
*/
class WebServiceContext
{
private $requestMessageBinder;
private $responseMessageBinder;
private $typeRepository;
private $converterRepository;
private $serviceDefinitionLoader;
private $wsdlFileDumper;
private $options;
private $serviceDefinition;
private $serviceBinder;
private $serverFactory;
public function __construct(LoaderInterface $loader, DumperInterface $dumper, MessageBinderInterface $requestMessageBinder, MessageBinderInterface $responseMessageBinder, TypeRepository $typeRepository, ConverterRepository $converterRepository, array $options)
{
$this->serviceDefinitionLoader = $loader;
$this->wsdlFileDumper = $dumper;
$this->requestMessageBinder = $requestMessageBinder;
$this->responseMessageBinder = $responseMessageBinder;
$this->typeRepository = $typeRepository;
$this->converterRepository = $converterRepository;
$this->options = $options;
}
public function getServiceDefinition()
{
if($this->serviceDefinition === null)
{
if(!$this->serviceDefinitionLoader->supports($this->options['resource'], $this->options['resource_type']))
{
throw new \LogicException();
}
$this->serviceDefinition = $this->serviceDefinitionLoader->load($this->options['resource'], $this->options['resource_type']);
$this->serviceDefinition->setName($this->options['name']);
$this->serviceDefinition->setNamespace($this->options['namespace']);
$this->typeRepository->fixTypeInformation($this->serviceDefinition);
}
return $this->serviceDefinition;
}
public function getWsdlFile($endpoint = null)
{
$file = sprintf('%s/%s.%s.wsdl', $this->options['cache_dir'], $this->options['name'], md5($endpoint));
$cache = new ConfigCache($file, $this->options['debug']);
if(!$cache->isFresh())
{
$cache->write($this->wsdlFileDumper->dumpServiceDefinition($this->getServiceDefinition(), array('endpoint' => $endpoint)));
}
return (string) $cache;
}
public function getWsdlFileContent($endpoint = null)
{
return file_get_contents($this->getWsdlFile($endpoint));
}
public function getServiceBinder()
{
if($this->serviceBinder === null)
{
$this->serviceBinder = new ServiceBinder($this->getServiceDefinition(), $this->requestMessageBinder, $this->responseMessageBinder);
}
return $this->serviceBinder;
}
public function getServerFactory()
{
if($this->serverFactory === null)
{
$this->serverFactory = new SoapServerFactory($this->getWsdlFile(), array(), $this->converterRepository);
}
return $this->serverFactory;
}
}