2016-11-08 19:01:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\Workflow;
|
|
|
|
|
2018-05-07 21:13:10 +01:00
|
|
|
use Symfony\Component\Workflow\Metadata\MetadataStoreInterface;
|
|
|
|
|
2016-11-08 19:01:05 +00:00
|
|
|
/**
|
|
|
|
* Builds a definition.
|
|
|
|
*
|
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
|
|
|
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
|
|
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
|
|
|
*/
|
|
|
|
class DefinitionBuilder
|
|
|
|
{
|
|
|
|
private $places = array();
|
|
|
|
private $transitions = array();
|
|
|
|
private $initialPlace;
|
2018-05-07 21:13:10 +01:00
|
|
|
private $metadataStore;
|
2016-11-08 19:01:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string[] $places
|
|
|
|
* @param Transition[] $transitions
|
|
|
|
*/
|
|
|
|
public function __construct(array $places = array(), array $transitions = array())
|
|
|
|
{
|
|
|
|
$this->addPlaces($places);
|
|
|
|
$this->addTransitions($transitions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Definition
|
|
|
|
*/
|
|
|
|
public function build()
|
|
|
|
{
|
2018-05-07 21:13:10 +01:00
|
|
|
return new Definition($this->places, $this->transitions, $this->initialPlace, $this->metadataStore);
|
2016-11-08 19:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear all data in the builder.
|
2017-03-09 15:56:40 +00:00
|
|
|
*
|
|
|
|
* @return $this
|
2016-11-08 19:01:05 +00:00
|
|
|
*/
|
2018-04-29 17:31:06 +01:00
|
|
|
public function clear()
|
2016-11-08 19:01:05 +00:00
|
|
|
{
|
|
|
|
$this->places = array();
|
|
|
|
$this->transitions = array();
|
|
|
|
$this->initialPlace = null;
|
2018-05-07 21:13:10 +01:00
|
|
|
$this->metadataStore = null;
|
2017-03-09 15:56:40 +00:00
|
|
|
|
|
|
|
return $this;
|
2016-11-08 19:01:05 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 15:56:40 +00:00
|
|
|
/**
|
2017-03-17 15:32:08 +00:00
|
|
|
* @param string $place
|
2017-03-20 10:06:58 +00:00
|
|
|
*
|
2017-03-09 15:56:40 +00:00
|
|
|
* @return $this
|
|
|
|
*/
|
2016-11-08 19:01:05 +00:00
|
|
|
public function setInitialPlace($place)
|
|
|
|
{
|
|
|
|
$this->initialPlace = $place;
|
2017-03-09 15:56:40 +00:00
|
|
|
|
|
|
|
return $this;
|
2016-11-08 19:01:05 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 15:56:40 +00:00
|
|
|
/**
|
2017-03-17 15:32:08 +00:00
|
|
|
* @param string $place
|
2017-03-20 10:06:58 +00:00
|
|
|
*
|
2017-03-09 15:56:40 +00:00
|
|
|
* @return $this
|
|
|
|
*/
|
2016-11-08 19:01:05 +00:00
|
|
|
public function addPlace($place)
|
|
|
|
{
|
|
|
|
if (!$this->places) {
|
|
|
|
$this->initialPlace = $place;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->places[$place] = $place;
|
2017-03-09 15:56:40 +00:00
|
|
|
|
|
|
|
return $this;
|
2016-11-08 19:01:05 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 15:56:40 +00:00
|
|
|
/**
|
2017-03-17 15:32:08 +00:00
|
|
|
* @param string[] $places
|
2017-03-20 10:06:58 +00:00
|
|
|
*
|
2017-03-09 15:56:40 +00:00
|
|
|
* @return $this
|
|
|
|
*/
|
2016-11-08 19:01:05 +00:00
|
|
|
public function addPlaces(array $places)
|
|
|
|
{
|
|
|
|
foreach ($places as $place) {
|
|
|
|
$this->addPlace($place);
|
|
|
|
}
|
2017-03-09 15:56:40 +00:00
|
|
|
|
|
|
|
return $this;
|
2016-11-08 19:01:05 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 13:57:19 +00:00
|
|
|
/**
|
|
|
|
* @param Transition[] $transitions
|
2017-03-09 15:56:40 +00:00
|
|
|
*
|
|
|
|
* @return $this
|
2016-12-06 13:57:19 +00:00
|
|
|
*/
|
2016-11-08 19:01:05 +00:00
|
|
|
public function addTransitions(array $transitions)
|
|
|
|
{
|
|
|
|
foreach ($transitions as $transition) {
|
|
|
|
$this->addTransition($transition);
|
|
|
|
}
|
2017-03-09 15:56:40 +00:00
|
|
|
|
|
|
|
return $this;
|
2016-11-08 19:01:05 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 15:56:40 +00:00
|
|
|
/**
|
|
|
|
* @return $this
|
|
|
|
*/
|
2016-11-08 19:01:05 +00:00
|
|
|
public function addTransition(Transition $transition)
|
|
|
|
{
|
|
|
|
$this->transitions[] = $transition;
|
2017-03-09 15:56:40 +00:00
|
|
|
|
|
|
|
return $this;
|
2016-11-08 19:01:05 +00:00
|
|
|
}
|
2018-04-29 17:31:06 +01:00
|
|
|
|
2018-05-07 21:13:10 +01:00
|
|
|
/**
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setMetadataStore(MetadataStoreInterface $metadataStore)
|
|
|
|
{
|
|
|
|
$this->metadataStore = $metadataStore;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2018-04-29 17:31:06 +01:00
|
|
|
/**
|
|
|
|
* @deprecated since Symfony 4.1, use the clear() method instead.
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function reset()
|
|
|
|
{
|
2018-05-03 09:46:26 +01:00
|
|
|
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "clear()" method instead.', __METHOD__), E_USER_DEPRECATED);
|
2018-04-29 17:31:06 +01:00
|
|
|
|
|
|
|
return $this->clear();
|
|
|
|
}
|
2016-11-08 19:01:05 +00:00
|
|
|
}
|