Added besimple.soap.cache service
This commit is contained in:
parent
502ba41935
commit
1a4e9246db
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the BeSimpleSoapBundle.
|
||||||
|
*
|
||||||
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BeSimple\SoapBundle;
|
||||||
|
|
||||||
|
use BeSimple\SoapCommon\Cache as BaseCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
|
*/
|
||||||
|
class Cache
|
||||||
|
{
|
||||||
|
public function __construct($disabled, $type, $directory, $lifetime = null, $limit = null)
|
||||||
|
{
|
||||||
|
BaseCache::setEnabled(!$disabled);
|
||||||
|
|
||||||
|
if (BaseCache::ENABLED == BaseCache::isEnabled()) {
|
||||||
|
BaseCache::setType($type);
|
||||||
|
BaseCache::setDirectory($directory);
|
||||||
|
|
||||||
|
if (null !== $lifetime) {
|
||||||
|
BaseCache::setLifetime($lifetime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $limit) {
|
||||||
|
BaseCache::setLimit($limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
* This file is part of the BeSimpleSoapBundle.
|
||||||
*
|
*
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
*
|
*
|
||||||
* This source file is subject to the MIT license that is bundled
|
* This source file is subject to the MIT license that is bundled
|
||||||
* with this source code in the file LICENSE.
|
* with this source code in the file LICENSE.
|
||||||
|
@ -10,6 +12,8 @@
|
||||||
|
|
||||||
namespace BeSimple\SoapBundle\DependencyInjection;
|
namespace BeSimple\SoapBundle\DependencyInjection;
|
||||||
|
|
||||||
|
use BeSimple\SoapCommon\Cache;
|
||||||
|
|
||||||
use Symfony\Component\Config\Definition\Processor;
|
use Symfony\Component\Config\Definition\Processor;
|
||||||
use Symfony\Component\Config\FileLocator;
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
@ -22,6 +26,7 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||||
* BeSimpleSoapExtension.
|
* BeSimpleSoapExtension.
|
||||||
*
|
*
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
*/
|
*/
|
||||||
class BeSimpleSoapExtension extends Extension
|
class BeSimpleSoapExtension extends Extension
|
||||||
{
|
{
|
||||||
|
@ -44,6 +49,8 @@ class BeSimpleSoapExtension extends Extension
|
||||||
|
|
||||||
$config = $processor->process($configuration->getConfigTree(), $configs);
|
$config = $processor->process($configuration->getConfigTree(), $configs);
|
||||||
|
|
||||||
|
$this->registerCacheConfiguration($config['cache'], $container, $loader);
|
||||||
|
|
||||||
if (isset($config['clients'])) {
|
if (isset($config['clients'])) {
|
||||||
$this->registerClientConfiguration($config['clients'], $container, $loader);
|
$this->registerClientConfiguration($config['clients'], $container, $loader);
|
||||||
}
|
}
|
||||||
|
@ -56,6 +63,33 @@ class BeSimpleSoapExtension extends Extension
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
||||||
|
{
|
||||||
|
$loader->load('soap.xml');
|
||||||
|
|
||||||
|
switch ($config['type']) {
|
||||||
|
case 'none':
|
||||||
|
$config['type'] = Cache::TYPE_NONE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'disk':
|
||||||
|
$config['type'] = Cache::TYPE_DISK;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'memory':
|
||||||
|
$config['type'] = Cache::TYPE_MEMORY;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'disk_memory':
|
||||||
|
$config['type'] = Cache::TYPE_DISK_MEMORY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (array('type', 'lifetime', 'limit') as $key) {
|
||||||
|
$container->setParameter('besimple.soap.cache.'.$key, $config[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function registerClientConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
private function registerClientConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
||||||
{
|
{
|
||||||
$loader->load('client.xml');
|
$loader->load('client.xml');
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the BeSimpleSoapBundle.
|
* This file is part of the BeSimpleSoapBundle.
|
||||||
*
|
*
|
||||||
* (c) Christian Kerl <christian-kerl@web.de>
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
*
|
*
|
||||||
* This source file is subject to the MIT license that is bundled
|
* This source file is subject to the MIT license that is bundled
|
||||||
* with this source code in the file LICENSE.
|
* with this source code in the file LICENSE.
|
||||||
|
@ -17,6 +19,7 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||||
* WebServiceExtension configuration structure.
|
* WebServiceExtension configuration structure.
|
||||||
*
|
*
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
*/
|
*/
|
||||||
class Configuration
|
class Configuration
|
||||||
{
|
{
|
||||||
|
@ -30,6 +33,7 @@ class Configuration
|
||||||
$treeBuilder = new TreeBuilder();
|
$treeBuilder = new TreeBuilder();
|
||||||
$rootNode = $treeBuilder->root('be_simple_soap');
|
$rootNode = $treeBuilder->root('be_simple_soap');
|
||||||
|
|
||||||
|
$this->addCacheSection($rootNode);
|
||||||
$this->addClientSection($rootNode);
|
$this->addClientSection($rootNode);
|
||||||
$this->addServicesSection($rootNode);
|
$this->addServicesSection($rootNode);
|
||||||
$this->addWsdlDumperSection($rootNode);
|
$this->addWsdlDumperSection($rootNode);
|
||||||
|
@ -37,6 +41,27 @@ class Configuration
|
||||||
return $treeBuilder->buildTree();
|
return $treeBuilder->buildTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function addCacheSection(ArrayNodeDefinition $rootNode)
|
||||||
|
{
|
||||||
|
$rootNode
|
||||||
|
->children()
|
||||||
|
->arrayNode('cache')
|
||||||
|
->children()
|
||||||
|
->scalarNode('type')
|
||||||
|
->defaultValue('disk')
|
||||||
|
->validate()
|
||||||
|
->ifNotInArray(array('none', 'disk', 'memory', 'disk_memory'))
|
||||||
|
->thenInvalid('The cache type has to be either "none", "disk", "memory" or "disk_memory"')
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->scalarNode('lifetime')->defaultNull()->end()
|
||||||
|
->scalarNode('limit')->defaultNull()->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
private function addClientSection(ArrayNodeDefinition $rootNode)
|
private function addClientSection(ArrayNodeDefinition $rootNode)
|
||||||
{
|
{
|
||||||
$rootNode
|
$rootNode
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
<argument type="collection">
|
<argument type="collection">
|
||||||
<argument key="debug">%kernel.debug%</argument>
|
<argument key="debug">%kernel.debug%</argument>
|
||||||
</argument>
|
</argument>
|
||||||
|
<argument type="service" id="besimple.soap.cache" />
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<container xmlns="http://symfony.com/schema/dic/services"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||||
|
|
||||||
|
<parameters>
|
||||||
|
<parameter key="besimple.soap.cache.class">BeSimple\SoapBundle\Cache</parameter>
|
||||||
|
<parameter key="besimple.soap.cache.directory">%kernel.cache_dir%/besimple/soap</parameter>
|
||||||
|
</parameters>
|
||||||
|
|
||||||
|
<services>
|
||||||
|
<service id="besimple.soap.cache" class="%besimple.soap.cache.class%">
|
||||||
|
<argument>%kernel.debug%</argument>
|
||||||
|
<argument>%besimple.soap.cache.type%</argument>
|
||||||
|
<argument>%besimple.soap.cache.directory%</argument>
|
||||||
|
<argument>%besimple.soap.cache.lifetime%</argument>
|
||||||
|
<argument>%besimple.soap.cache.limit%</argument>
|
||||||
|
</service>
|
||||||
|
</services>
|
||||||
|
|
||||||
|
</container>
|
|
@ -32,6 +32,7 @@
|
||||||
<argument key="binder_request_class">%besimple.soap.binder.request.rpcliteral.class%</argument>
|
<argument key="binder_request_class">%besimple.soap.binder.request.rpcliteral.class%</argument>
|
||||||
<argument key="binder_response_class">%besimple.soap.binder.response.rpcliteral.class%</argument>
|
<argument key="binder_response_class">%besimple.soap.binder.response.rpcliteral.class%</argument>
|
||||||
</argument>
|
</argument>
|
||||||
|
<argument type="service" id="besimple.soap.cache" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="besimple.soap.context.documentwrapped" class="%besimple.soap.context.class%" abstract="true">
|
<service id="besimple.soap.context.documentwrapped" class="%besimple.soap.context.class%" abstract="true">
|
||||||
|
@ -46,6 +47,7 @@
|
||||||
<argument key="binder_request_class">%besimple.soap.binder.request.documentwrapped.class%</argument>
|
<argument key="binder_request_class">%besimple.soap.binder.request.documentwrapped.class%</argument>
|
||||||
<argument key="binder_response_class">%besimple.soap.binder.response.documentwrapped.class%</argument>
|
<argument key="binder_response_class">%besimple.soap.binder.response.documentwrapped.class%</argument>
|
||||||
</argument>
|
</argument>
|
||||||
|
<argument type="service" id="besimple.soap.cache" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="besimple.soap.definition.dumper.wsdl.rpcliteral" class="%besimple.soap.definition.dumper.wsdl.rpcliteral.class%">
|
<service id="besimple.soap.definition.dumper.wsdl.rpcliteral" class="%besimple.soap.definition.dumper.wsdl.rpcliteral.class%">
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
namespace BeSimple\SoapBundle\Soap;
|
namespace BeSimple\SoapBundle\Soap;
|
||||||
|
|
||||||
use BeSimple\SoapBundle\Converter\ConverterRepository;
|
use BeSimple\SoapBundle\Converter\ConverterRepository;
|
||||||
|
use BeSimple\SoapCommon\Cache;
|
||||||
use Zend\Soap\Wsdl;
|
use Zend\Soap\Wsdl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +40,7 @@ class SoapServerFactory
|
||||||
'classmap' => $this->classmap,
|
'classmap' => $this->classmap,
|
||||||
'typemap' => $this->createSoapServerTypemap($request, $response),
|
'typemap' => $this->createSoapServerTypemap($request, $response),
|
||||||
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
|
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
|
||||||
'cache_wsdl' => $this->debug ? WSDL_CACHE_NONE : WSDL_CACHE_DISK,
|
'cache_wsdl' => Cache::getType(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue