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.
89 lines
1.8 KiB
89 lines
1.8 KiB
<?php
|
|
|
|
namespace Zitec\RuleEngineBundle\DoctrineBehaviors;
|
|
|
|
use Zitec\RuleEngineBundle\Entity\Rule;
|
|
use Zitec\RuleEngineBundle\Service\RuleContextInterface;
|
|
|
|
/**
|
|
* Class RuleTrait
|
|
* A trait that can be used in an entity class to add rule behavior to it.
|
|
* It is recommended that you use it in conjecture with RuleInterface.
|
|
*/
|
|
trait PreconditionTrait
|
|
{
|
|
|
|
|
|
/**
|
|
* @ORM\OneToOne(targetEntity="Zitec\RuleEngineBundle\Entity\Rule",cascade={"persist"})
|
|
* @ORM\JoinColumn(name="precondicion_id", referencedColumnName="id")
|
|
*
|
|
*/
|
|
private $precondition;
|
|
|
|
/**
|
|
* @var RuleContextInterface
|
|
*/
|
|
private $contextObjectPrecondition;
|
|
|
|
|
|
/**
|
|
* Get rule
|
|
*
|
|
* @return Rule
|
|
*/
|
|
public function getPrecondition(): ?Rule
|
|
{
|
|
return $this->precondition;
|
|
}
|
|
/**
|
|
* Set rule
|
|
*
|
|
* @param null|Rule $rule
|
|
*
|
|
* @return self
|
|
*/
|
|
public function setPrecondition(?Rule $rule = null)
|
|
{
|
|
$this->precondition = $rule;
|
|
|
|
return $this;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return RuleContextInterface
|
|
*/
|
|
public function getContextObjectPrecondition(): RuleContextInterface
|
|
{
|
|
return $this->contextObjectPrecondition;
|
|
}
|
|
|
|
/**
|
|
* @param RuleContextInterface $contextObject
|
|
*
|
|
* @return self
|
|
*/
|
|
public function setContextObject(RuleContextInterface $contextObject)
|
|
{
|
|
$this->contextObjectPrecondition = $contextObject;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function __toString()
|
|
{
|
|
$rule = $this->getPrecondition();
|
|
if ($rule instanceof Rule) {
|
|
$name = $rule->getName();
|
|
if (isset($name)){
|
|
return $name;
|
|
}
|
|
}
|
|
|
|
return "New precondition";
|
|
}
|
|
}
|