[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/symfony/twig-bridge/Extension/ -> WorkflowExtension.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Bridge\Twig\Extension;
  13  
  14  use Symfony\Component\Workflow\Registry;
  15  use Symfony\Component\Workflow\Transition;
  16  use Twig\Extension\AbstractExtension;
  17  use Twig\TwigFunction;
  18  
  19  /**
  20   * WorkflowExtension.
  21   *
  22   * @author Grégoire Pineau <lyrixx@lyrixx.info>
  23   */
  24  class WorkflowExtension extends AbstractExtension
  25  {
  26      private $workflowRegistry;
  27  
  28      public function __construct(Registry $workflowRegistry)
  29      {
  30          $this->workflowRegistry = $workflowRegistry;
  31      }
  32  
  33      public function getFunctions()
  34      {
  35          return [
  36              new TwigFunction('workflow_can', [$this, 'canTransition']),
  37              new TwigFunction('workflow_transitions', [$this, 'getEnabledTransitions']),
  38              new TwigFunction('workflow_has_marked_place', [$this, 'hasMarkedPlace']),
  39              new TwigFunction('workflow_marked_places', [$this, 'getMarkedPlaces']),
  40          ];
  41      }
  42  
  43      /**
  44       * Returns true if the transition is enabled.
  45       *
  46       * @param object $subject        A subject
  47       * @param string $transitionName A transition
  48       * @param string $name           A workflow name
  49       *
  50       * @return bool true if the transition is enabled
  51       */
  52      public function canTransition($subject, $transitionName, $name = null)
  53      {
  54          return $this->workflowRegistry->get($subject, $name)->can($subject, $transitionName);
  55      }
  56  
  57      /**
  58       * Returns all enabled transitions.
  59       *
  60       * @param object $subject A subject
  61       * @param string $name    A workflow name
  62       *
  63       * @return Transition[] All enabled transitions
  64       */
  65      public function getEnabledTransitions($subject, $name = null)
  66      {
  67          return $this->workflowRegistry->get($subject, $name)->getEnabledTransitions($subject);
  68      }
  69  
  70      /**
  71       * Returns true if the place is marked.
  72       *
  73       * @param object $subject   A subject
  74       * @param string $placeName A place name
  75       * @param string $name      A workflow name
  76       *
  77       * @return bool true if the transition is enabled
  78       */
  79      public function hasMarkedPlace($subject, $placeName, $name = null)
  80      {
  81          return $this->workflowRegistry->get($subject, $name)->getMarking($subject)->has($placeName);
  82      }
  83  
  84      /**
  85       * Returns marked places.
  86       *
  87       * @param object $subject        A subject
  88       * @param bool   $placesNameOnly If true, returns only places name. If false returns the raw representation
  89       * @param string $name           A workflow name
  90       *
  91       * @return string[]|int[]
  92       */
  93      public function getMarkedPlaces($subject, $placesNameOnly = true, $name = null)
  94      {
  95          $places = $this->workflowRegistry->get($subject, $name)->getMarking($subject)->getPlaces();
  96  
  97          if ($placesNameOnly) {
  98              return array_keys($places);
  99          }
 100  
 101          return $places;
 102      }
 103  
 104      public function getName()
 105      {
 106          return 'workflow';
 107      }
 108  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1