Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.04 KB | None | 0 0
  1. <?php
  2. namespace Bold\CermIntegration\Model\GammaProject\Command\Dispatcher;
  3.  
  4. use Bold\CermIntegration\Exception\GammaProjectValidatorException;
  5. use Bold\CermIntegration\Validator\GammaProject\GammaProjectValidatorInterface;
  6. use Bold\CermIntegration\Model\GammaProject\Command\GammaProjectPersistCommandInterface;
  7. use Bold\CermIntegration\Model\ResourceModel\GammaProjectResourceModel;
  8. use Magento\Framework\Exception\CouldNotSaveException;
  9. use Bold\Logger\Logger;
  10.  
  11. class GammaProjectPersistCommandDispatcher implements GammaProjectPersistCommandDispatcherInterface
  12. {
  13.     /**
  14.      * @var GammaProjectValidatorInterface
  15.      */
  16.     private $gammaProjectValidator;
  17.  
  18.     /**
  19.      * @var GammaProjectResourceModel
  20.      */
  21.     private $gammaProjectResourceModel;
  22.  
  23.     /**
  24.      * @var Logger
  25.      */
  26.     private $logger;
  27.  
  28.     /**
  29.      * @param GammaProjectValidatorInterface $gammaProjectValidator
  30.      * @param GammaProjectResourceModel $gammaProjectResourceModel
  31.      * @param Logger $logger
  32.      */
  33.     public function __construct(
  34.         GammaProjectValidatorInterface $gammaProjectValidator,
  35.         GammaProjectResourceModel $gammaProjectResourceModel,
  36.         Logger $logger
  37.     ) {
  38.         $this->gammaProjectValidator = $gammaProjectValidator;
  39.         $this->gammaProjectResourceModel = $gammaProjectResourceModel;
  40.         $this->logger = $logger;
  41.     }
  42.  
  43.     /**
  44.      * {@inheritdoc}
  45.      */
  46.     public function dispatch(GammaProjectPersistCommandInterface $command)
  47.     {
  48.         $gammaProject = $command->getGammaProject();
  49.         $result = $this->gammaProjectValidator->isSatisfiedBy($gammaProject);
  50.  
  51.         if (!empty($result)) {
  52.             throw new GammaProjectValidatorException(__('Validation Gamma Project Error'), null, 0, $result);
  53.         }
  54.  
  55.         try {
  56.             $this->gammaProjectResourceModel->save($gammaProject);
  57.         } catch (\PDOException $e) {
  58.             $this->logger->error($e->getMessage());
  59.             throw new CouldNotSaveException(__('Could not save Gamma Project'), $e);
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement