Licitator 1.0
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

5 years ago
  1. <?php
  2. namespace Zitec\RuleEngineBundle\DoctrineBehaviors;
  3. use Zitec\RuleEngineBundle\Entity\Rule;
  4. use Zitec\RuleEngineBundle\Service\RuleContextInterface;
  5. /**
  6. * Class RuleTrait
  7. * A trait that can be used in an entity class to add rule behavior to it.
  8. * It is recommended that you use it in conjecture with RuleInterface.
  9. */
  10. trait PreconditionTrait
  11. {
  12. /**
  13. * @ORM\OneToOne(targetEntity="Zitec\RuleEngineBundle\Entity\Rule",cascade={"persist"})
  14. * @ORM\JoinColumn(name="precondicion_id", referencedColumnName="id")
  15. *
  16. */
  17. private $precondition;
  18. /**
  19. * @var RuleContextInterface
  20. */
  21. private $contextObjectPrecondition;
  22. /**
  23. * Get rule
  24. *
  25. * @return Rule
  26. */
  27. public function getPrecondition(): ?Rule
  28. {
  29. return $this->precondition;
  30. }
  31. /**
  32. * Set rule
  33. *
  34. * @param null|Rule $rule
  35. *
  36. * @return self
  37. */
  38. public function setPrecondition(?Rule $rule = null)
  39. {
  40. $this->precondition = $rule;
  41. return $this;
  42. }
  43. /**
  44. * @return RuleContextInterface
  45. */
  46. public function getContextObjectPrecondition(): RuleContextInterface
  47. {
  48. return $this->contextObjectPrecondition;
  49. }
  50. /**
  51. * @param RuleContextInterface $contextObject
  52. *
  53. * @return self
  54. */
  55. public function setContextObject(RuleContextInterface $contextObject)
  56. {
  57. $this->contextObjectPrecondition = $contextObject;
  58. return $this;
  59. }
  60. /**
  61. * @return string
  62. */
  63. public function __toString()
  64. {
  65. $rule = $this->getPrecondition();
  66. if ($rule instanceof Rule) {
  67. $name = $rule->getName();
  68. if (isset($name)){
  69. return $name;
  70. }
  71. }
  72. return "New precondition";
  73. }
  74. }