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

Open in your IDE?
  1. <?php
  2. namespace Pimcore\Workflow\MarkingStore;
  3. use Pimcore\Model\DataObject\Concrete;
  4. use Symfony\Component\PropertyAccess\PropertyAccess;
  5. use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
  6. use Symfony\Component\Workflow\Exception\LogicException;
  7. use Symfony\Component\Workflow\Marking;
  8. use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
  9. class DataObjectMultipleStateMarkingStore extends MultipleStateMarkingStore
  10. {
  11.     private $property;
  12.     private $propertyAccessor;
  13.     /**
  14.      * @param string                         $property
  15.      * @param PropertyAccessorInterface|null $propertyAccessor
  16.      */
  17.     public function __construct($property 'marking'PropertyAccessorInterface $propertyAccessor null)
  18.     {
  19.         parent::__construct($property$propertyAccessor);
  20.         $this->property $property;
  21.         $this->propertyAccessor $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
  22.     }
  23.     /**
  24.      * @inheritdoc
  25.      *
  26.      * @throws LogicException
  27.      */
  28.     public function getMarking($subject)
  29.     {
  30.         $this->checkIfSubjectIsValid($subject);
  31.         $marking = (array) $this->propertyAccessor->getValue($subject$this->property);
  32.         $_marking = [];
  33.         foreach ($marking as $place) {
  34.             $_marking[$place] = 1;
  35.         }
  36.         return new Marking($_marking);
  37.     }
  38.     /**
  39.      * @inheritdoc
  40.      *
  41.      * @throws LogicException
  42.      * @throws \Exception
  43.      */
  44.     public function setMarking($subjectMarking $marking)
  45.     {
  46.         $subject $this->checkIfSubjectIsValid($subject);
  47.         $places array_keys($marking->getPlaces());
  48.         $this->propertyAccessor->setValue($subject$this->property$places);
  49.     }
  50.     /**
  51.      * @param object $subject
  52.      *
  53.      * @return Concrete
  54.      */
  55.     private function checkIfSubjectIsValid($subject): Concrete
  56.     {
  57.         if (!$subject instanceof Concrete) {
  58.             throw new LogicException('data_object_multiple_state marking store works for pimcore data objects only.');
  59.         }
  60.         return $subject;
  61.     }
  62. }