Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Commit

Permalink
Fixed SF4 compatibility, removed support for non-supported dependency…
Browse files Browse the repository at this point in the history
… versions
  • Loading branch information
Tobias Feijten committed May 26, 2020
1 parent da91b5b commit d00f80f
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 72 deletions.
16 changes: 6 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
# - nightly
# - hhvm
- 7.2
- 7.3
- 7.4

services:
- memcached

env:
- PECL_MEMCACHE=memcache-3.0.6
- PECL_MEMCACHE=memcache-3.0.8
- PECL_MEMCACHE=memcache-3.0.9

before_script:
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then yes "" | pecl install -f "$PECL_MEMCACHE"; fi;'
- yes "" | pecl install -f "$PECL_MEMCACHE"
# Need to activate memchached extension explictly to work with all versions.
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then phpenv config-add .travis-php.ini; fi;'
- phpenv config-add .travis-php.ini;
- composer self-update || true
# Ensure the memcache extension is available
- composer show --platform ext-memcache
Expand Down
2 changes: 0 additions & 2 deletions Command/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Lsw\MemcacheBundle\Command;

use Lsw\MemcacheBundle\Cache\AntiDogPileMemcache;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -63,7 +62,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
* @param OutputInterface $output Output interface
*
* @see Command
* @return mixed
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
Expand Down
15 changes: 7 additions & 8 deletions DataCollector/MemcacheDataCollector.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace Lsw\MemcacheBundle\DataCollector;

use Symfony\Component\Yaml\Yaml;

use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -55,11 +53,11 @@ public function collect(Request $request, Response $response, \Exception $except
$this->data['pools']['calls'][$name] = $calls;
$this->data['pools']['options'][$name] = $this->options[$name];
}
$this->data['pools']['statistics'] = $this->calculateStatistics($this->data['pools']['calls']);
$this->data['pools']['statistics'] = $this->calculateStatistics();
$this->data['total']['statistics'] = $this->calculateTotalStatistics($this->data['pools']['statistics']);
}

private function calculateStatistics($calls)
private function calculateStatistics()
{
$statistics = array();
foreach ($this->data['pools']['calls'] as $name => $calls) {
Expand Down Expand Up @@ -128,8 +126,6 @@ public function getTotals()

/**
* Method returns all logged Memcache call objects
*
* @return mixed
*/
public function getCalls()
{
Expand All @@ -138,8 +134,6 @@ public function getCalls()

/**
* Method returns all Memcache options
*
* @return mixed
*/
public function getOptions()
{
Expand All @@ -153,4 +147,9 @@ public function getName()
{
return 'memcache';
}

public function reset()
{
$this->data = [];
}
}
68 changes: 38 additions & 30 deletions DependencyInjection/LswMemcacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public function load(array $configs, ContainerBuilder $container)
if (isset($config['session'])) {
$this->enableSessionSupport($config, $container);
} else {
$container->setParameter('memcache.session_handler.auto_load',false);
$container->setParameter('memcache.session_handler.auto_load',false);
}
if (isset($config['doctrine'])) {
$this->loadDoctrine($config, $container);
$this->loadDoctrine($config, $container);
}
if (isset($config['firewall'])) {
$this->loadFirewall($config, $container);
$this->loadFirewall($config, $container);
}
if (isset($config['pools'])) {
$this->addClients($config['pools'], $container);
Expand All @@ -50,7 +50,7 @@ public function load(array $configs, ContainerBuilder $container)
/**
* Enables session support using Memcache based on the configuration
*
* @param string $config Configuration for bundle
* @param array $config Configuration for bundle
* @param ContainerBuilder $container Service container
*
* @return void
Expand Down Expand Up @@ -85,7 +85,11 @@ private function enableSessionSupport($config, ContainerBuilder $container)
$definition
->addArgument(new Reference(sprintf('memcache.%s', $pool)))
->addArgument($options);
$this->addClassesToCompile(array($definition->getClass()));
if (method_exists($this, 'addAnnotatedClassesToCompile')) { // SF3.3+
$this->addAnnotatedClassesToCompile([$definition->getClass()]);
} else { // <SF3.3
$this->addClassesToCompile([$definition->getClass()]);
}
}

/**
Expand Down Expand Up @@ -135,31 +139,35 @@ protected function loadDoctrine(array $config, ContainerBuilder $container)
*/
protected function loadFirewall(array $config, ContainerBuilder $container)
{
// make sure the pool is specified and it exists
$pool = $config['firewall']['pool'];
if (null === $pool) {
return;
}
if (!isset($config['pools']) || !isset($config['pools'][$pool])) {
throw new \LogicException(sprintf('The pool "%s" does not exist! Cannot enable the firewall!', $pool));
}
// calculate options
$options = array();
$options['prefix'] = $config['firewall']['prefix'];
$options['concurrency'] = $config['firewall']['concurrency'];
$options['spin_lock_wait'] = $config['firewall']['spin_lock_wait'];
$options['lock_max_wait'] = $config['firewall']['lock_max_wait'];
$options['reverse_proxies'] = $config['firewall']['reverse_proxies'];
$options['x_forwarded_for'] = $config['firewall']['x_forwarded_for'];
// load the firewall handler
$definition = new Definition($container->getParameter('memcache.firewall_handler.class'));
$container->setDefinition('memcache.firewall_handler', $definition);
$definition
->addArgument(new Reference(sprintf('memcache.%s', $pool)))
->addArgument($options);
$definition->addTag('kernel.event_listener', array('event'=>'kernel.request','method'=>'onKernelRequest'));
$definition->addTag('kernel.event_listener', array('event'=>'kernel.terminate','method'=>'onKernelTerminate'));
$this->addClassesToCompile(array($definition->getClass()));
// make sure the pool is specified and it exists
$pool = $config['firewall']['pool'];
if (null === $pool) {
return;
}
if (!isset($config['pools']) || !isset($config['pools'][$pool])) {
throw new \LogicException(sprintf('The pool "%s" does not exist! Cannot enable the firewall!', $pool));
}
// calculate options
$options = array();
$options['prefix'] = $config['firewall']['prefix'];
$options['concurrency'] = $config['firewall']['concurrency'];
$options['spin_lock_wait'] = $config['firewall']['spin_lock_wait'];
$options['lock_max_wait'] = $config['firewall']['lock_max_wait'];
$options['reverse_proxies'] = $config['firewall']['reverse_proxies'];
$options['x_forwarded_for'] = $config['firewall']['x_forwarded_for'];
// load the firewall handler
$definition = new Definition($container->getParameter('memcache.firewall_handler.class'));
$container->setDefinition('memcache.firewall_handler', $definition);
$definition
->addArgument(new Reference(sprintf('memcache.%s', $pool)))
->addArgument($options);
$definition->addTag('kernel.event_listener', array('event'=>'kernel.request','method'=>'onKernelRequest'));
$definition->addTag('kernel.event_listener', array('event'=>'kernel.terminate','method'=>'onKernelTerminate'));
if (method_exists($this, 'addAnnotatedClassesToCompile')) { // SF3.3+
$this->addAnnotatedClassesToCompile([$definition->getClass()]);
} else { // <SF3.3
$this->addClassesToCompile([$definition->getClass()]);
}
}

/**
Expand Down
23 changes: 7 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,19 @@ It has full Web Debug Toolbar integration that allows you to analyze and debug t

### Requirements

- PHP 5.3.10 or higher
- PHP 7.2 or higher
- php-memcache 3.0.6 or higher
- memcached 1.4 or higher

NB: This bundle no longer uses the PHP "memcached" extension that uses "libmemcached", see "Considerations".

PHP7 support is currently (experimentally) available by compiling and installing: https://github.com/websupport-sk/pecl-memcache/tree/php7
PHP7 support is available by compiling and installing: https://github.com/websupport-sk/pecl-memcache/tree/php7

### Installation

To install LswMemcacheBundle with Composer just add the following to your 'composer.json' file:
To install LswMemcacheBundle with Composer just execute the following command:

{
require: {
"leaseweb/memcache-bundle": "*",
...
}
}

The next thing you should do is install the bundle by executing the following command:

php composer.phar update leaseweb/memcache-bundle
php composer.phar require kick-in/memcache-bundle

Finally, add the bundle to the registerBundles function of the AppKernel class in the 'app/AppKernel.php' file:

Expand All @@ -67,9 +58,9 @@ lsw_memcache:
Install the following dependencies (in Debian based systems using 'apt'):
apt-get install memcached php5-memcache
apt-get install memcached php-memcache
Do not forget to restart you web server after adding the Memcache module. Now the Memcache
Do not forget to restart your web server after adding the Memcache module. Now the Memcache
information should show up with a little double arrow (fast-forward) icon in your debug toolbar.
### Usage
Expand Down Expand Up @@ -220,7 +211,7 @@ Please note:

LswMemcacheBundle uses the 'memcache' PHP extension (memcached client) and not the libmemcache based 'memcached' PHP extension.

Major version 1 of this bundle used the other extension. In major version 2 of this bundle the full featured version 3.0.8 of PECL "memcache" (without the 'd') was chosen, due to it's complete feature set and good design and support.
Major version 1 of this bundle used the other extension. In major version 2 of this bundle the full featured version 3.0.8 of PECL "memcache" (without the 'd') was chosen, due to its complete feature set and good design and support.

### Known issues

Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "leaseweb/memcache-bundle",
"name": "kick-in/memcache-bundle",
"type": "symfony-bundle",
"description": "Memcache Doctrine caching and session storage in the Web Debug Toolbar",
"keywords": ["memcache","memcached","cache","session"],
Expand All @@ -12,20 +12,19 @@
}
],
"require": {
"php": ">=5.3.2",
"symfony/framework-bundle": ">=2.1",
"php": ">=7.2",
"symfony/framework-bundle": ">=3.4",
"ext-memcache": ">=3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"autoload": {
"psr-0": { "Lsw\\MemcacheBundle": "" }
"psr-4": { "Lsw\\MemcacheBundle\\": "" }
},
"target-dir": "Lsw/MemcacheBundle",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
"dev-master": "3.x-dev"
}
}
}

0 comments on commit d00f80f

Please sign in to comment.