bundles/SaintElmos/BaseBundle/EventListener/TestListener.php line 27

Open in your IDE?
  1. <?php
  2. namespace SaintElmos\BaseBundle\EventListener;
  3. use Pimcore\Event\Model\ElementEventInterface;
  4. use Pimcore\Event\Model\DataObjectEvent;
  5. use Pimcore\Event\Model\AssetEvent;
  6. use Pimcore\Event\Model\DocumentEvent;
  7. use SaintElmos\BaseBundle\Services\Configuration;
  8. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  9. use Psr\Log\LoggerInterface;
  10. class TestListener {
  11.     private $setConf;
  12.     private $logger;
  13.     public function __construct(Configuration $setConfLoggerInterface $logger)
  14.     {
  15.         $this->setConf $setConf;
  16.         $this->logger $logger;
  17.     }
  18.     public function onPreUpdate (ElementEventInterface $e) {
  19.         if($e instanceof AssetEvent) {
  20.             // do something with the asset
  21.             $foo $e->getAsset();
  22.         } else if ($e instanceof DocumentEvent) {
  23.             // do something with the document
  24.             $foo $e->getDocument();
  25.         } else if ($e instanceof DataObjectEvent) {
  26.             // do something with the object
  27.             $foo $e->getObject();
  28.             //$foo->setMyValue(microtime(true));
  29.             // we don't have to call save here as we are in the pre-update event anyway ;-)
  30.         }
  31.     }
  32.     /**
  33.      * @param FilterControllerEvent $event
  34.      */
  35.     public function onKernelController(FilterControllerEvent $event)
  36.     {
  37.         if(!isset($this->setConf->INIT)) {
  38.             $this->setConf->INIT true;
  39.             $this->logger->debug('TestListener::onKernelController #############################################################################');
  40.         }
  41.     }
  42. }