<?php
namespace Rawafed\CloudServicesBundle\Service;
use Rawafed\CloudServicesBundle\Entity\Subscription;
use Rawafed\CloudServicesBundle\Event\SubscriptionCreatedEvent;
use Rawafed\CloudServicesBundle\Event\SubscriptionUpdatedEvent;
use Rawafed\TaskQueueBundle\Service\TaskQueue;
class SubscriptionInstaller
{
private $taskQueue;
public function __construct(TaskQueue $taskQueue)
{
$this->taskQueue = $taskQueue;
}
public function install(Subscription $subscription)
{
$this->taskQueue->addTask('install_subscription', [
'id' => $subscription->getId(),
]);
}
public function update(Subscription $subscription)
{
$this->taskQueue->addTask('update_subscription', [
'id' => $subscription->getId(),
]);
}
public function onSubscriptionCreated(SubscriptionCreatedEvent $event)
{
$subscription = $event->getSubscription();
$this->install($subscription);
}
public function onSubscriptionUpdated(SubscriptionUpdatedEvent $event)
{
$subscription = $event->getSubscription();
$this->update($subscription);
}
}