vendor/pimcore/pimcore/lib/Workflow/MarkingStore/DataObjectMultipleStateMarkingStore.php line 25

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Workflow\MarkingStore;
  15. use Pimcore\Model\DataObject\Concrete;
  16. use Symfony\Component\PropertyAccess\PropertyAccess;
  17. use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
  18. use Symfony\Component\Workflow\Exception\LogicException;
  19. use Symfony\Component\Workflow\Marking;
  20. use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
  21. class DataObjectMultipleStateMarkingStore extends MultipleStateMarkingStore
  22. {
  23.     private $property;
  24.     private $propertyAccessor;
  25.     /**
  26.      * @param string                         $property
  27.      * @param PropertyAccessorInterface|null $propertyAccessor
  28.      */
  29.     public function __construct($property 'marking'PropertyAccessorInterface $propertyAccessor null)
  30.     {
  31.         parent::__construct($property$propertyAccessor);
  32.         $this->property $property;
  33.         $this->propertyAccessor $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
  34.     }
  35.     /**
  36.      * @inheritdoc
  37.      *
  38.      * @throws LogicException
  39.      */
  40.     public function getMarking($subject)
  41.     {
  42.         $this->checkIfSubjectIsValid($subject);
  43.         $marking = (array) $this->propertyAccessor->getValue($subject$this->property);
  44.         $_marking = [];
  45.         foreach ($marking as $place) {
  46.             $_marking[$place] = 1;
  47.         }
  48.         return new Marking($_marking);
  49.     }
  50.     /**
  51.      * @inheritdoc
  52.      *
  53.      * @throws LogicException
  54.      * @throws \Exception
  55.      */
  56.     public function setMarking($subjectMarking $marking)
  57.     {
  58.         $subject $this->checkIfSubjectIsValid($subject);
  59.         $places array_keys($marking->getPlaces());
  60.         $this->propertyAccessor->setValue($subject$this->property$places);
  61.     }
  62.     /**
  63.      * @param object $subject
  64.      *
  65.      * @return Concrete
  66.      */
  67.     private function checkIfSubjectIsValid($subject): Concrete
  68.     {
  69.         if (!$subject instanceof Concrete) {
  70.             throw new LogicException('data_object_multiple_state marking store works for pimcore data objects only.');
  71.         }
  72.         return $subject;
  73.     }
  74. }