diff --git a/.travis.yml b/.travis.yml index 7417ae6..aa00575 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Command/ClearCommand.php b/Command/ClearCommand.php index b325152..e967a2f 100644 --- a/Command/ClearCommand.php +++ b/Command/ClearCommand.php @@ -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; @@ -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) { diff --git a/DataCollector/MemcacheDataCollector.php b/DataCollector/MemcacheDataCollector.php index 01a1d98..0735585 100644 --- a/DataCollector/MemcacheDataCollector.php +++ b/DataCollector/MemcacheDataCollector.php @@ -1,8 +1,6 @@ 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) { @@ -128,8 +126,6 @@ public function getTotals() /** * Method returns all logged Memcache call objects - * - * @return mixed */ public function getCalls() { @@ -138,8 +134,6 @@ public function getCalls() /** * Method returns all Memcache options - * - * @return mixed */ public function getOptions() { @@ -153,4 +147,9 @@ public function getName() { return 'memcache'; } + + public function reset() + { + $this->data = []; + } } diff --git a/DependencyInjection/LswMemcacheExtension.php b/DependencyInjection/LswMemcacheExtension.php index 565ff38..eb05d57 100644 --- a/DependencyInjection/LswMemcacheExtension.php +++ b/DependencyInjection/LswMemcacheExtension.php @@ -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); @@ -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 @@ -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 { // addClassesToCompile([$definition->getClass()]); + } } /** @@ -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 { // addClassesToCompile([$definition->getClass()]); + } } /** diff --git a/README.md b/README.md index 85c1bbd..2370e65 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 @@ -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 diff --git a/composer.json b/composer.json index d430696..06ec389 100644 --- a/composer.json +++ b/composer.json @@ -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"], @@ -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" } } }