for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\CacheBundle\Invalidation;
use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\ODM\PHPCR\Event;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DoctrinePHPCRODMListenerContainerAware implements EventSubscriber
{
protected $listener;
protected $service;
/**
* @param ContainerInterface $container
* @param $service
public function __construct(ContainerInterface $container, $service)
$this->container = $container;
container
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$this->service = $service;
}
* @return array
public function getSubscribedEvents()
return array(
Event::preRemove,
Event::preUpdate,
);
* @param $args
public function preRemove(LifecycleEventArgs $args)
$this->load();
$this->listener->preRemove($args);
* @param LifecycleEventArgs $args
public function preUpdate(LifecycleEventArgs $args)
$this->listener->preUpdate($args);
private function load()
if ($this->listener) {
return;
$this->listener = $this->container->get($this->service);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: