From 70da526fd49389438fc142f4dfb35e6e1c1cb24f Mon Sep 17 00:00:00 2001 From: Christian Kerl Date: Thu, 7 Apr 2011 21:54:53 +0200 Subject: [PATCH] added WebServiceContext class; SoapWebServiceController now uses WebServiceContext to acquire all objects needed to handle a request for a certain service; --- Controller/SoapWebServiceController.php | 25 ++++--- WebServiceContext.php | 89 +++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 WebServiceContext.php diff --git a/Controller/SoapWebServiceController.php b/Controller/SoapWebServiceController.php index 3090872..99d89ed 100644 --- a/Controller/SoapWebServiceController.php +++ b/Controller/SoapWebServiceController.php @@ -8,19 +8,20 @@ * with this source code in the file LICENSE. */ -namespace Bundle\WebServiceBundle; - - -use Bundle\WebServiceBundle\Soap\SoapServerFactory; +namespace Bundle\WebServiceBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\ContainerAware; + use Bundle\WebServiceBundle\Soap\SoapRequest; use Bundle\WebServiceBundle\Soap\SoapResponse; use Bundle\WebServiceBundle\Soap\SoapHeader; +use Bundle\WebServiceBundle\Soap\SoapServerFactory; use Bundle\WebServiceBundle\ServiceBinding\ServiceBinder; @@ -78,13 +79,13 @@ class SoapWebServiceController extends ContainerAware public function handle($webservice) { - $serviceConfiguration = $this->serviceConfigurationFactory->create($webservice); + $webServiceContext = $this->container->get('webservice.context.' . $webservice); $this->soapRequest = SoapRequest::createFromHttpRequest($this->container->get('request')); - $this->serviceBinder = $serviceConfiguration->createServiceBinder(); + $this->serviceBinder = $webServiceContext->getServiceBinder(); - $this->soapServer = $serviceConfiguration->createServer($this->soapRequest, $this->soapResponse); + $this->soapServer = $webServiceContext->getServerFactory()->create($this->soapRequest, $this->soapResponse); $this->soapServer->setObject($this); ob_start(); @@ -99,14 +100,16 @@ class SoapWebServiceController extends ContainerAware } public function definition($webservice) - { - $serviceConfiguration = $this->serviceConfigurationFactory->create($webservice); + { + $webServiceContext = $this->container->get('webservice.context.' . $webservice); $request = $this->container->get('request'); if($request->query->has('WSDL')) { - // dump wsdl file - // return + $response = new Response(file_get_contents($webServiceContext->getWsdlFile())); + $response->headers->set('Content-Type', 'application/wsdl+xml'); + + return $response; } else { diff --git a/WebServiceContext.php b/WebServiceContext.php new file mode 100644 index 0000000..0f34b0d --- /dev/null +++ b/WebServiceContext.php @@ -0,0 +1,89 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Bundle\WebServiceBundle; + +/** + * WebServiceContext. + * + * @author Christian Kerl + */ +use Bundle\WebServiceBundle\ServiceDefinition\Dumper\DumperInterface; + +use Bundle\WebServiceBundle\ServiceBinding\MessageBinderInterface; + +use Bundle\WebServiceBundle\Converter\ConverterRepository; + +use Bundle\WebServiceBundle\ServiceBinding\ServiceBinder; + +use Bundle\WebServiceBundle\Soap\SoapServerFactory; + +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) + { + + } + + ; + } + + public function getWsdlFile() + { + ; + } + + 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; + } +} \ No newline at end of file