Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Bold\CermIntegration\Model\GammaProject\Command\Dispatcher;
- use Bold\CermIntegration\Exception\GammaProjectValidatorException;
- use Bold\CermIntegration\Validator\GammaProject\GammaProjectValidatorInterface;
- use Bold\CermIntegration\Model\GammaProject\Command\GammaProjectPersistCommandInterface;
- use Bold\CermIntegration\Model\ResourceModel\GammaProjectResourceModel;
- use Magento\Framework\Exception\CouldNotSaveException;
- use Bold\Logger\Logger;
- class GammaProjectPersistCommandDispatcher implements GammaProjectPersistCommandDispatcherInterface
- {
- /**
- * @var GammaProjectValidatorInterface
- */
- private $gammaProjectValidator;
- /**
- * @var GammaProjectResourceModel
- */
- private $gammaProjectResourceModel;
- /**
- * @var Logger
- */
- private $logger;
- /**
- * @param GammaProjectValidatorInterface $gammaProjectValidator
- * @param GammaProjectResourceModel $gammaProjectResourceModel
- * @param Logger $logger
- */
- public function __construct(
- GammaProjectValidatorInterface $gammaProjectValidator,
- GammaProjectResourceModel $gammaProjectResourceModel,
- Logger $logger
- ) {
- $this->gammaProjectValidator = $gammaProjectValidator;
- $this->gammaProjectResourceModel = $gammaProjectResourceModel;
- $this->logger = $logger;
- }
- /**
- * {@inheritdoc}
- */
- public function dispatch(GammaProjectPersistCommandInterface $command)
- {
- $gammaProject = $command->getGammaProject();
- $result = $this->gammaProjectValidator->isSatisfiedBy($gammaProject);
- if (!empty($result)) {
- throw new GammaProjectValidatorException(__('Validation Gamma Project Error'), null, 0, $result);
- }
- try {
- $this->gammaProjectResourceModel->save($gammaProject);
- } catch (\PDOException $e) {
- $this->logger->error($e->getMessage());
- throw new CouldNotSaveException(__('Could not save Gamma Project'), $e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement