<?php
/**
* Created by PhpStorm.
* User: sergey
* Date: 10/16/14
* Time: 5:34 PM
*/
namespace Sindrive\ContentBundle\Listener;
use Sindrive\ContentBundle\Edgecast\PurgeQueue;
use Symfony\Component\EventDispatcher\GenericEvent;
class PurgeQueueListener
{
/**
* @var PurgeQueue
*/
private $purgeQueue;
/**
* @var string
*/
private $resourcesPath;
public function __construct(PurgeQueue $purgeQueue, $resourcesPath)
{
$this->purgeQueue = $purgeQueue;
$this->resourcesPath = $resourcesPath;
}
public function onDelete(GenericEvent $event)
{
$values = array_merge($event->getArgument('thumbs'), (array)$event->getArgument('image'));
$resourcesPath = $this->resourcesPath;
array_walk($values, function(&$value) use ($resourcesPath) {
$value = '/' . trim(str_replace($resourcesPath, '', $value), '/');
});
$this->purgeQueue->add($values);
}
}