src/Modules/TangibleAsset/Event/Subscriber/ChangeAssetOwner.php line 64

Open in your IDE?
  1. <?php
  2. namespace App\Modules\TangibleAsset\Event\Subscriber;
  3. use App\Modules\Contract\Entity\Form\BuySell;
  4. use App\Modules\Contract\Event\FormFinalized;
  5. use App\Modules\Contract\Service\ParticipantDetailsService;
  6. use App\Modules\TangibleAsset\Entity\AssetListing;
  7. use App\Modules\TangibleAsset\Entity\AssetOwner;
  8. use App\Modules\TangibleAsset\Factory\AssetAbstractFactory;
  9. use App\Modules\TangibleAsset\Service\AssetDetailsService;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class ChangeAssetOwner implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var ParticipantDetailsService
  15.      */
  16.     private $participantDetailsService;
  17.     /**
  18.      * @var AssetDetailsService
  19.      */
  20.     private $assetDetailsService;
  21.     /**
  22.      * @var AssetAbstractFactory
  23.      */
  24.     private $assetAbstractFactory;
  25.     public function __construct(
  26.         ParticipantDetailsService $participantDetailsService,
  27.         AssetDetailsService $assetDetailsService,
  28.         AssetAbstractFactory $assetAbstractFactory
  29.     )
  30.     {
  31.         $this->participantDetailsService $participantDetailsService;
  32.         $this->assetDetailsService $assetDetailsService;
  33.         $this->assetAbstractFactory $assetAbstractFactory;
  34.     }
  35.     /**
  36.      * Returns an array of event names this subscriber wants to listen to.
  37.      *
  38.      * The array keys are event names and the value can be:
  39.      *
  40.      *  * The method name to call (priority defaults to 0)
  41.      *  * An array composed of the method name to call and the priority
  42.      *  * An array of arrays composed of the method names to call and respective
  43.      *    priorities, or 0 if unset
  44.      *
  45.      * For instance:
  46.      *
  47.      *  * ['eventName' => 'methodName']
  48.      *  * ['eventName' => ['methodName', $priority]]
  49.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  50.      *
  51.      * @return array The event names to listen to
  52.      */
  53.     public static function getSubscribedEvents()
  54.     {
  55.         return [
  56.             FormFinalized::class => 'onFormFinalized',
  57.         ];
  58.     }
  59.     public function onFormFinalized(FormFinalized $event)
  60.     {
  61.         $form $event->getForm();
  62.         $contract $form->getContract();
  63.         $asset $contract->getAsset();
  64.         if ($form->getType() != BuySell::TYPE || is_null($asset)) {
  65.             return;
  66.         }
  67.         $executor $contract->getExecutor();
  68.         /** @var AssetOwner $executorDetails */
  69.         $executorDetails $this->participantDetailsService->get($executor->getId(), $executor->getType());
  70.         $assetDetails $this->assetDetailsService->get($asset->getId(), $asset->getType());
  71.         if ($assetDetails->isListing()) {
  72.             /** @var  $assetDetails AssetListing*/
  73.             $assetDetails $assetDetails->getAsset();
  74.         }
  75.         $assetService $this->assetAbstractFactory->createAssetService($assetDetails->getType());
  76.         $assetService->changeAssetOwner($assetDetails$executorDetails->getAssetOwnerID());
  77.     }
  78. }