BeSimpleSoap/WebServiceContext.php

105 lines
3.3 KiB
PHP
Raw Normal View History

<?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;
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 <christian-kerl@web.de>
*/
class WebServiceContext
{
private $converterRepository;
private $requestMessageBinder;
private $responseMessageBinder;
2011-07-14 17:45:03 +02:00
private $serviceDefinitionLoader;
private $wsdlFileDumper;
2011-07-14 17:45:03 +02:00
private $options;
2011-07-14 17:45:03 +02:00
private $serviceDefinition;
private $serviceBinder;
private $serverFactory;
2011-07-14 17:45:03 +02:00
public function __construct(LoaderInterface $loader, DumperInterface $dumper, ConverterRepository $converterRepository, MessageBinderInterface $requestMessageBinder, MessageBinderInterface $responseMessageBinder, array $options)
{
$this->serviceDefinitionLoader = $loader;
$this->wsdlFileDumper = $dumper;
2011-07-14 17:45:03 +02:00
$this->converterRepository = $converterRepository;
$this->requestMessageBinder = $requestMessageBinder;
$this->responseMessageBinder = $responseMessageBinder;
2011-07-14 17:45:03 +02:00
$this->options = $options;
}
2011-07-14 17:45:03 +02:00
public function getServiceDefinition()
{
2011-07-14 17:45:03 +02:00
if($this->serviceDefinition === null) {
if(!$this->serviceDefinitionLoader->supports($this->options['resource'], $this->options['resource_type'])) {
throw new \LogicException();
}
2011-07-14 17:45:03 +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']);
}
2011-07-14 17:45:03 +02:00
return $this->serviceDefinition;
}
2011-07-14 17:45:03 +02:00
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);
2011-07-14 17:45:03 +02:00
if(!$cache->isFresh()) {
$cache->write($this->wsdlFileDumper->dumpServiceDefinition($this->getServiceDefinition(), array('endpoint' => $endpoint)));
}
2011-07-14 17:45:03 +02:00
return $file;
}
2011-07-14 17:45:03 +02:00
public function getWsdlFileContent($endpoint = null)
{
return file_get_contents($this->getWsdlFile($endpoint));
}
2011-07-14 17:45:03 +02:00
public function getServiceBinder()
{
2011-07-14 17:45:03 +02:00
if($this->serviceBinder === null) {
$this->serviceBinder = new ServiceBinder($this->getServiceDefinition(), $this->requestMessageBinder, $this->responseMessageBinder);
}
2011-07-14 17:45:03 +02:00
return $this->serviceBinder;
}
2011-07-14 17:45:03 +02:00
public function getServerFactory()
{
2011-07-14 17:45:03 +02:00
if($this->serverFactory === null) {
$this->serverFactory = new SoapServerFactory($this->getServiceDefinition(), $this->getWsdlFile(), $this->converterRepository);
}
2011-07-14 17:45:03 +02:00
return $this->serverFactory;
}
}