You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.7 KiB
61 lines
1.7 KiB
<?php
|
|
|
|
namespace Zitec\RuleEngineBundle\Service;
|
|
|
|
use Doctrine\ORM\EntityManager;
|
|
use Zitec\RuleEngineBundle\DoctrineBehaviors\PostconditionInterface;
|
|
use Zitec\RuleEngineBundle\DoctrineBehaviors\PreconditionInterface;
|
|
use Zitec\RuleEngineBundle\DoctrineBehaviors\RuleInterface;
|
|
|
|
/**
|
|
* Class RuleEngineOrchestrator
|
|
*
|
|
* @package Zitec\RuleEngineBundle\Service
|
|
*/
|
|
class Orchestrator
|
|
{
|
|
|
|
/**
|
|
* @var EntityManager
|
|
*/
|
|
protected $entityManager;
|
|
|
|
/**
|
|
* @var RuleConditionsManager[]
|
|
*/
|
|
protected $conditionsManagers;
|
|
|
|
/**
|
|
* RuleEngineOrchestrator constructor.
|
|
*
|
|
* @param EntityManager $entityManager
|
|
*/
|
|
public function __construct(EntityManager $entityManager)
|
|
{
|
|
$this->entityManager = $entityManager;
|
|
}
|
|
|
|
/**
|
|
* @param string $entityName
|
|
* @param RuleConditionsManager $conditionsManager
|
|
*/
|
|
public function setEntityConditionsManager(string $entityName, RuleConditionsManager $conditionsManager)
|
|
{
|
|
$entityClassName = $this->entityManager->getMetadataFactory()->getMetadataFor($entityName)->getName();
|
|
$this->conditionsManagers[$entityClassName] = $conditionsManager;
|
|
}
|
|
|
|
/**
|
|
* @param RuleInterface|PreconditionInterface|PostconditionInterface $entity
|
|
* @return RuleConditionsManager
|
|
*/
|
|
public function getConditionsManagerForEntity( $entity)
|
|
{
|
|
$entityClassName = get_class($entity);
|
|
if (!isset($this->conditionsManagers[$entityClassName])) {
|
|
throw new \InvalidArgumentException(sprintf('No conditions manager defined for entity %s', $entityClassName));
|
|
}
|
|
|
|
return $this->conditionsManagers[$entityClassName];
|
|
}
|
|
}
|