2011-04-07 21:54:53 +02:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* This file is part of the WebServiceBundle.
|
|
|
|
*
|
|
|
|
* (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 Bundle\WebServiceBundle;
|
|
|
|
|
|
|
|
|
2011-04-08 00:46:58 +02:00
|
|
|
use Symfony\Component\Config\ConfigCache;
|
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface;
|
2011-04-07 21:54:53 +02:00
|
|
|
|
|
|
|
use Bundle\WebServiceBundle\Converter\ConverterRepository;
|
|
|
|
use Bundle\WebServiceBundle\ServiceBinding\ServiceBinder;
|
2011-04-08 00:46:58 +02:00
|
|
|
use Bundle\WebServiceBundle\ServiceBinding\MessageBinderInterface;
|
|
|
|
use Bundle\WebServiceBundle\ServiceDefinition\Dumper\DumperInterface;
|
2011-04-07 21:54:53 +02:00
|
|
|
use Bundle\WebServiceBundle\Soap\SoapServerFactory;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
private $converterRepository;
|
|
|
|
private $requestMessageBinder;
|
|
|
|
private $responseMessageBinder;
|
|
|
|
|
|
|
|
private $serviceDefinitionLoader;
|
|
|
|
private $wsdlFileDumper;
|
|
|
|
|
|
|
|
private $options;
|
|
|
|
|
|
|
|
private $serviceDefinition;
|
|
|
|
private $serviceBinder;
|
|
|
|
private $serverFactory;
|
|
|
|
|
|
|
|
public function __construct(LoaderInterface $loader, DumperInterface $dumper, ConverterRepository $converterRepository, MessageBinderInterface $requestMessageBinder, MessageBinderInterface $responseMessageBinder, array $options)
|
|
|
|
{
|
|
|
|
$this->serviceDefinitionLoader = $loader;
|
|
|
|
$this->wsdlFileDumper = $dumper;
|
|
|
|
|
|
|
|
$this->converterRepository = $converterRepository;
|
|
|
|
$this->requestMessageBinder = $requestMessageBinder;
|
|
|
|
$this->responseMessageBinder = $responseMessageBinder;
|
|
|
|
|
|
|
|
$this->options = $options;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getServiceDefinition()
|
|
|
|
{
|
|
|
|
if($this->serviceDefinition === null)
|
|
|
|
{
|
2011-04-08 00:46:58 +02:00
|
|
|
if(!$this->serviceDefinitionLoader->supports($this->options['resource'], $this->options['resource_type']))
|
|
|
|
{
|
|
|
|
throw new \LogicException();
|
|
|
|
}
|
2011-04-07 21:54:53 +02:00
|
|
|
|
2011-04-08 00:46:58 +02:00
|
|
|
$this->serviceDefinition = $this->serviceDefinitionLoader->load($this->options['resource'], $this->options['resource_type']);
|
|
|
|
$this->serviceDefinition->setName($this->options['name']);
|
|
|
|
$this->serviceDefinition->setNamespace($this->options['namespace']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->serviceDefinition;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getWsdlFile($endpoint = null)
|
|
|
|
{
|
|
|
|
$id = $endpoint !== null ? '.' . md5($endpoint) : '';
|
|
|
|
$file = sprintf('%s/%s.wsdl', $this->options['cache_dir'], $this->options['name'] . $id);
|
|
|
|
$cache = new ConfigCache($file, true);
|
|
|
|
|
|
|
|
if(!$cache->isFresh())
|
|
|
|
{
|
|
|
|
$cache->write($this->wsdlFileDumper->dumpServiceDefinition($this->getServiceDefinition(), array('endpoint' => $endpoint)));
|
2011-04-07 21:54:53 +02:00
|
|
|
}
|
|
|
|
|
2011-04-08 00:46:58 +02:00
|
|
|
return $file;
|
2011-04-07 21:54:53 +02:00
|
|
|
}
|
|
|
|
|
2011-04-08 00:46:58 +02:00
|
|
|
public function getWsdlFileContent($endpoint = null)
|
2011-04-07 21:54:53 +02:00
|
|
|
{
|
2011-04-08 00:46:58 +02:00
|
|
|
return file_get_contents($this->getWsdlFile($endpoint));
|
2011-04-07 21:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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->getServiceDefinition(), $this->getWsdlFile(), $this->converterRepository);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->serverFactory;
|
|
|
|
}
|
|
|
|
}
|