Skip to content

Commit

Permalink
Merge pull request #108 from MyOnlineStore/update-bundle-sf-4
Browse files Browse the repository at this point in the history
Made bundle compatible with symfony 3.4
  • Loading branch information
tedivm committed Apr 4, 2019
2 parents ec24fa1 + a540bd6 commit 337f0bc
Show file tree
Hide file tree
Showing 23 changed files with 165 additions and 110 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
- 7.1
- 7.2
- 7.3

before_install:
- composer self-update
Expand Down
2 changes: 2 additions & 0 deletions Adapters/DoctrineAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
*/

namespace Tedivm\StashBundle\Adapters;

use Doctrine\Common\Cache\Cache as DoctrineCacheInterface;

/**
* Class DoctrineAdapter
*
* @package Tedivm\StashBundle\Adapters
* @author Josh Hall-Bachner <[email protected]>
* @author Robert Hafner <[email protected]>
Expand Down
6 changes: 6 additions & 0 deletions Collector/CacheDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

namespace Tedivm\StashBundle\Collector;

use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -152,4 +153,9 @@ public function getname()
{
return 'stash';
}

public function reset()
{
$this->data = [];
}
}
38 changes: 22 additions & 16 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ public function getConfigTreeBuilder()

$rootNode
->beforeNormalization()
->ifTrue(function ($v) { return is_array($v) && !array_key_exists('default_cache', $v) && array_key_exists('caches', $v); })
->ifTrue(function ($v) {
return is_array($v) && !array_key_exists('default_cache', $v) && array_key_exists('caches', $v);
})
->then(function ($v) {
return Configuration::normalizeDefaultCacheConfig($v);
})
->end()
->beforeNormalization()
->ifTrue(function ($v) { return is_array($v) && !array_key_exists('caches', $v) && !array_key_exists('cache', $v); })
->ifTrue(function ($v) {
return is_array($v) && !array_key_exists('caches', $v) && !array_key_exists('cache', $v);
})
->then(function ($v) {
return Configuration::normalizeCacheConfig($v);
})
Expand Down Expand Up @@ -105,7 +109,9 @@ public function getCachesNode()
->fixXmlConfig('handler')
->fixXmlConfig('driver')
->beforeNormalization()
->ifTrue(function ($v) { return is_array($v) && array_key_exists('handlers', $v); })
->ifTrue(function ($v) {
return is_array($v) && array_key_exists('handlers', $v);
})
->then(function ($v) {
return Configuration::normalizeHandlerToDriverConfig($v);
})
Expand Down Expand Up @@ -152,8 +158,8 @@ public function addDriverSettings($driver, NodeBuilder $rootNode)
->arrayNode($driver)
->fixXmlConfig('server');

if ($driver == 'Memcache') {
$finalNode = $driverNode
if ($driver == 'Memcache') {
$finalNode = $driverNode
->info('All options except "servers" are Memcached options. See http://www.php.net/manual/en/memcached.constants.php')
->addDefaultsIfNotSet()
->children()
Expand Down Expand Up @@ -193,8 +199,8 @@ public function addDriverSettings($driver, NodeBuilder $rootNode)
->end()
->end()
;
} elseif ($driver == 'Redis') {
$finalNode = $driverNode
} elseif ($driver == 'Redis') {
$finalNode = $driverNode
->info("Accepts server info, password, and database.")
->addDefaultsIfNotSet()
->children()
Expand All @@ -216,26 +222,26 @@ public function addDriverSettings($driver, NodeBuilder $rootNode)
->end()
->end()
;
} else {
$defaults = isset($this->driverSettings[$driver]) ? $this->driverSettings[$driver] : array();
} else {
$defaults = isset($this->driverSettings[$driver]) ? $this->driverSettings[$driver] : array();

$node = $driverNode
$node = $driverNode
->addDefaultsIfNotSet()
->children();

foreach ($defaults as $setting => $default) {
$node
foreach ($defaults as $setting => $default) {
$node
->scalarNode($setting)
->defaultValue($default)
->end()
;
}
}

$finalNode = $node->end()
$finalNode = $node->end()
;
}
}

$finalNode->end()
$finalNode->end()
;
}

Expand Down
86 changes: 48 additions & 38 deletions DependencyInjection/TedivmStashExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Config\FileLocator;
Expand Down Expand Up @@ -88,57 +88,68 @@ protected function addCacheService($name, $cache, $container)
unset($cache['registerSessionHandler']);

$container
->setDefinition(sprintf('stash.driver.%s_cache', $name), new DefinitionDecorator('stash.driver'))
->setArguments(array(
$drivers,
$cache
))
->setAbstract(false)
;
->setDefinition(sprintf('stash.driver.%s_cache', $name), new ChildDefinition('stash.driver'))
->setArguments(
[
$drivers,
$cache,
]
)
->setAbstract(false);

$container
->setDefinition(sprintf('stash.tracker.%s_cache', $name), new DefinitionDecorator('stash.tracker'))
->setArguments(array(
$name
))
->addMethodCall('enableQueryLogging', array($logqueries))
->addMethodCall('enableQueryValueLogging', array($logQueryValues))
->setAbstract(false)
;

$cacheDefinition = new DefinitionDecorator('stash.cache');
->setDefinition(sprintf('stash.tracker.%s_cache', $name), new ChildDefinition('stash.tracker'))
->setArguments(
[
$name,
]
)
->addMethodCall('enableQueryLogging', [$logqueries])
->addMethodCall('enableQueryValueLogging', [$logQueryValues])
->setAbstract(false);

$cacheDefinition = new ChildDefinition('stash.cache');
$container
->setDefinition(sprintf('stash.%s_cache', $name), $cacheDefinition)
->setArguments(array(
$name,
new Reference(sprintf('stash.driver.%s_cache', $name)),
new Reference(sprintf('stash.tracker.%s_cache', $name))
))
->setAbstract(false)
;
->setArguments(
[
$name,
new Reference(sprintf('stash.driver.%s_cache', $name)),
new Reference(sprintf('stash.tracker.%s_cache', $name)),
]
)
->setAbstract(false);

if (isset($cache['logger']) && $cache['logger']) {
$cacheDefinition->addMethodCall('setLogger', array(new Reference($cache['logger'])));
}

if (interface_exists("\\Doctrine\\Common\\Cache\\Cache") && $doctrine) {
$container
->setDefinition(sprintf('stash.adapter.doctrine.%s_cache', $name), new DefinitionDecorator('stash.adapter.doctrine'))
->setArguments(array(
new Reference(sprintf('stash.%s_cache', $name))
))
->setAbstract(false)
;
->setDefinition(
sprintf('stash.adapter.doctrine.%s_cache', $name),
new ChildDefinition('stash.adapter.doctrine')
)
->setArguments(
[
new Reference(sprintf('stash.%s_cache', $name)),
]
)
->setAbstract(false);
}

if ($session) {
$container
->setDefinition(sprintf('stash.adapter.session.%s_cache', $name), new DefinitionDecorator('stash.adapter.session'))
->setArguments(array(
new Reference(sprintf('stash.%s_cache', $name))
))
->setAbstract(false)
;
->setDefinition(
sprintf('stash.adapter.session.%s_cache', $name),
new ChildDefinition('stash.adapter.session')
)
->setArguments(
[
new Reference(sprintf('stash.%s_cache', $name)),
]
)
->setAbstract(false);
}

$container
Expand All @@ -147,7 +158,6 @@ protected function addCacheService($name, $cache, $container)
new Reference(sprintf('stash.tracker.%s_cache', $name))
))
;

}

/**
Expand Down
2 changes: 1 addition & 1 deletion Factory/DriverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

namespace Tedivm\StashBundle\Factory;

use Stash\DriverList;
use Stash\Interfaces\DriverInterface;

Expand All @@ -37,7 +38,6 @@ public static function createDriver($types, $options)
$h = array();

foreach ($types as $type) {

if (!isset($drivers[$type])) {
$allDrivers = DriverList::getAllDrivers();

Expand Down
2 changes: 1 addition & 1 deletion Service/CacheItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

namespace Tedivm\StashBundle\Service;

use Stash\Item;

/**
Expand Down Expand Up @@ -52,5 +53,4 @@ public function get($invalidation = 0, $arg = null, $arg2 = null)

return $result;
}

}
5 changes: 3 additions & 2 deletions Service/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

namespace Tedivm\StashBundle\Service;

use Stash\DriverList;
use Stash\Interfaces\DriverInterface;
use Stash\Pool;
Expand Down Expand Up @@ -47,7 +48,7 @@ public function __construct($name, DriverInterface $driver = null, CacheTracker
$this->setNamespace($name);

if (isset($driver)) {
$this->setDriver($driver);
$this->setDriver($driver);
}

parent::__construct($driver);
Expand All @@ -62,7 +63,7 @@ public function getItem($key)
$item = parent::getItem($key);

if (isset($this->tracker)) {
$item->setCacheTracker($this->tracker);
$item->setCacheTracker($this->tracker);
}

return $item;
Expand Down
1 change: 0 additions & 1 deletion TedivmStashBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
class TedivmStashBundle extends Bundle
{

public function getContainerExtension()
{
return new TedivmStashExtension();
Expand Down
3 changes: 0 additions & 3 deletions Tests/Adapters/DoctrineAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,9 @@ protected function _getCacheDriver()

public function testDeleteAllAndNamespaceVersioningBetweenCaches()
{

}

public function testFlushAllAndNamespaceVersioningBetweenCaches()
{

}

}
1 change: 0 additions & 1 deletion Tests/Adapters/SessionHandlerAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ public function testClearAll()
$this->assertEquals('', $sessionB->read('session_id'), 'SessionB cleared after ClearAll');
$this->assertEquals('', $sessionC->read('session_id'), 'SessionC cleared after ClearAll');
}

}
28 changes: 21 additions & 7 deletions Tests/Collector/CacheDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@

namespace Tedivm\StashBundle\Tests\Collector;

use \Stash\DriverList;
use \Tedivm\StashBundle\Service\CacheTracker as Tracker;
use PHPUnit\Framework\TestCase;
use Stash\DriverList;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Tedivm\StashBundle\Service\CacheTracker as Tracker;

/**
* Class CacheDataCollectorTest
* @package Tedivm\StashBundle\Tests\Collector
* @author Josh Hall-Bachner <[email protected]>
* @author Robert Hafner <[email protected]>
*/
class CacheDataCollectorTest extends \PHPUnit_Framework_TestCase
class CacheDataCollectorTest extends TestCase
{
protected $testClass = 'Tedivm\StashBundle\Collector\CacheDataCollector';

Expand Down Expand Up @@ -121,17 +124,28 @@ public function testGetAvailableDrivers()

//var_dump($drivers, $systemDrivers);exit();
foreach ($drivers as $driver) {
$this->assertTrue(in_array($driver, $systemDrivers),
'getDrivers returns only registered drivers- Unregistered: ' . $driver);
self::assertTrue(
in_array($driver, $systemDrivers),
'getDrivers returns only registered drivers- Unregistered: ' . $driver
);
}
}

public function testResetWillSetDataToEmptyArray()
{
$collector = $this->getPrimedCollector();

self::assertNotSame('a:0:{}', $collector->serialize());
$collector->reset();
self::assertSame('a:0:{}', $collector->serialize());
}

protected function getPrimedCollector()
{
$collector = $this->getPopulatedCollector();

$requestMock = $this->getMock('Symfony\Component\HttpFoundation\Request');
$responseMock = $this->getMock('Symfony\Component\HttpFoundation\Response');
$requestMock = $this->createMock(Request::class);
$responseMock = $this->createMock(Response::class);

$collector->collect($requestMock, $responseMock);

Expand Down
Loading

0 comments on commit 337f0bc

Please sign in to comment.