2011-04-07 21:54:53 +02:00
|
|
|
<?php
|
|
|
|
/*
|
2011-07-18 22:43:12 +02:00
|
|
|
* This file is part of the BeSimpleSoapBundle.
|
2011-04-07 21:54:53 +02:00
|
|
|
*
|
|
|
|
* (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.
|
|
|
|
*/
|
|
|
|
|
2011-07-18 22:43:12 +02:00
|
|
|
namespace BeSimple\SoapBundle;
|
2011-04-07 21:54:53 +02:00
|
|
|
|
2011-07-18 22:43:12 +02:00
|
|
|
use BeSimple\SoapBundle\Converter\ConverterRepository;
|
|
|
|
use BeSimple\SoapBundle\Converter\TypeRepository;
|
|
|
|
use BeSimple\SoapBundle\ServiceBinding\MessageBinderInterface;
|
|
|
|
use BeSimple\SoapBundle\ServiceBinding\ServiceBinder;
|
|
|
|
use BeSimple\SoapBundle\ServiceDefinition\Dumper\DumperInterface;
|
|
|
|
use BeSimple\SoapBundle\Soap\SoapServerFactory;
|
2011-04-07 21:54:53 +02:00
|
|
|
|
2011-07-17 10:46:54 +02:00
|
|
|
use Symfony\Component\Config\ConfigCache;
|
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface;
|
|
|
|
|
2011-04-08 00:46:58 +02:00
|
|
|
/**
|
|
|
|
* WebServiceContext.
|
|
|
|
*
|
|
|
|
* @author Christian Kerl <christian-kerl@web.de>
|
|
|
|
*/
|
2011-04-07 21:54:53 +02:00
|
|
|
class WebServiceContext
|
|
|
|
{
|
2011-08-14 18:00:28 +02:00
|
|
|
private $requestHeaderMessageBinder;
|
2011-04-07 21:54:53 +02:00
|
|
|
private $requestMessageBinder;
|
|
|
|
private $responseMessageBinder;
|
2011-07-17 15:08:46 +02:00
|
|
|
private $typeRepository;
|
|
|
|
private $converterRepository;
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-04-07 21:54:53 +02:00
|
|
|
private $wsdlFileDumper;
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-04-07 21:54:53 +02:00
|
|
|
private $options;
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-04-07 21:54:53 +02:00
|
|
|
private $serviceDefinition;
|
|
|
|
private $serviceBinder;
|
|
|
|
private $serverFactory;
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-08-14 18:00:28 +02:00
|
|
|
public function __construct(LoaderInterface $loader, DumperInterface $dumper, MessageBinderInterface $requestHeaderMessageBinder, MessageBinderInterface $requestMessageBinder, MessageBinderInterface $responseMessageBinder, TypeRepository $typeRepository, ConverterRepository $converterRepository, array $options) {
|
2011-07-17 10:46:54 +02:00
|
|
|
$this->loader = $loader;
|
2011-04-07 21:54:53 +02:00
|
|
|
$this->wsdlFileDumper = $dumper;
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-08-14 18:00:28 +02:00
|
|
|
$this->requestHeaderMessageBinder = $requestHeaderMessageBinder;
|
|
|
|
$this->requestMessageBinder = $requestMessageBinder;
|
|
|
|
$this->responseMessageBinder = $responseMessageBinder;
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-07-17 15:08:46 +02:00
|
|
|
$this->typeRepository = $typeRepository;
|
|
|
|
$this->converterRepository = $converterRepository;
|
|
|
|
|
2011-04-07 21:54:53 +02:00
|
|
|
$this->options = $options;
|
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
|
|
|
|
public function getServiceDefinition()
|
2011-04-07 21:54:53 +02:00
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
if (null === $this->serviceDefinition) {
|
|
|
|
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']));
|
2011-04-08 00:46:58 +02:00
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-07-17 10:46:54 +02:00
|
|
|
$this->serviceDefinition = $this->loader->load($this->options['resource'], $this->options['resource_type']);
|
2011-04-08 00:46:58 +02:00
|
|
|
$this->serviceDefinition->setName($this->options['name']);
|
|
|
|
$this->serviceDefinition->setNamespace($this->options['namespace']);
|
2011-07-17 15:08:46 +02:00
|
|
|
|
|
|
|
$this->typeRepository->fixTypeInformation($this->serviceDefinition);
|
2011-04-08 00:46:58 +02:00
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-04-08 00:46:58 +02:00
|
|
|
return $this->serviceDefinition;
|
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-07-23 20:06:42 +02:00
|
|
|
public function getWsdlFileContent($endpoint = null)
|
|
|
|
{
|
|
|
|
return file_get_contents($this->getWsdlFile($endpoint));
|
|
|
|
}
|
|
|
|
|
2011-04-08 00:46:58 +02:00
|
|
|
public function getWsdlFile($endpoint = null)
|
|
|
|
{
|
2011-07-17 15:08:46 +02:00
|
|
|
$file = sprintf('%s/%s.%s.wsdl', $this->options['cache_dir'], $this->options['name'], md5($endpoint));
|
|
|
|
$cache = new ConfigCache($file, $this->options['debug']);
|
2011-07-14 17:45:03 +02:00
|
|
|
|
|
|
|
if(!$cache->isFresh()) {
|
2011-04-08 00:46:58 +02:00
|
|
|
$cache->write($this->wsdlFileDumper->dumpServiceDefinition($this->getServiceDefinition(), array('endpoint' => $endpoint)));
|
2011-04-07 21:54:53 +02:00
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-07-17 15:08:46 +02:00
|
|
|
return (string) $cache;
|
2011-04-07 21:54:53 +02:00
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
|
|
|
|
public function getServiceBinder()
|
2011-04-07 21:54:53 +02:00
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
if (null === $this->serviceBinder) {
|
2011-08-14 18:00:28 +02:00
|
|
|
$this->serviceBinder = new ServiceBinder($this->getServiceDefinition(), $this->requestHeaderMessageBinder, $this->requestMessageBinder, $this->responseMessageBinder);
|
2011-04-07 21:54:53 +02:00
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-04-07 21:54:53 +02:00
|
|
|
return $this->serviceBinder;
|
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
|
|
|
|
public function getServerFactory()
|
2011-04-07 21:54:53 +02:00
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
if (null === $this->serverFactory) {
|
2011-07-17 15:08:46 +02:00
|
|
|
$this->serverFactory = new SoapServerFactory($this->getWsdlFile(), array(), $this->converterRepository, $this->options['debug']);
|
2011-04-07 21:54:53 +02:00
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-04-07 21:54:53 +02:00
|
|
|
return $this->serverFactory;
|
|
|
|
}
|
|
|
|
}
|