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.

88 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 PostconditionTrait
  11. {
  12. /**
  13. * @ORM\OneToOne(targetEntity="Zitec\RuleEngineBundle\Entity\Rule",cascade={"persist"})
  14. * @ORM\JoinColumn(name="postcondicion_id", referencedColumnName="id")
  15. */
  16. private $postcondition;
  17. /**
  18. * @var RuleContextInterface
  19. */
  20. private $contextObjectPostcondition;
  21. /**
  22. * Get rule
  23. *
  24. * @return Rule
  25. */
  26. public function getPostcondition(): ?Rule
  27. {
  28. return $this->postcondition;
  29. }
  30. /**
  31. * Set rule
  32. *
  33. * @param null|Rule $rule
  34. *
  35. * @return self
  36. */
  37. public function setPostcondition(?Rule $rule = null)
  38. {
  39. $this->postcondition = $rule;
  40. return $this;
  41. }
  42. /**
  43. * @return RuleContextInterface
  44. */
  45. public function getContextObjectPostcondition(): RuleContextInterface
  46. {
  47. return $this->contextObjectPostcondition;
  48. }
  49. /**
  50. * @param RuleContextInterface $contextObject
  51. *
  52. * @return self
  53. */
  54. public function setContextObjectPostcondition(RuleContextInterface $contextObject)
  55. {
  56. $this->contextObjectPostcondition = $contextObject;
  57. return $this;
  58. }
  59. /**
  60. * @return string
  61. */
  62. public function __toString()
  63. {
  64. $rule = $this->getPostcondition();
  65. if ($rule instanceof Rule) {
  66. $name = $rule->getName();
  67. if (isset($name)){
  68. return $name;
  69. }
  70. }
  71. return "New postcondition";
  72. }
  73. }