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.

33 lines
685B

  1. <?php
  2. namespace common\logic;
  3. use common\logic\Producer\Producer\Model\Producer;
  4. use yii\base\ErrorException;
  5. trait ProducerContextTrait
  6. {
  7. protected ?Producer $producerContext = null;
  8. public function setProducerContext(Producer $producer): self
  9. {
  10. $this->producerContext = $producer;
  11. return $this;
  12. }
  13. public function getProducerContext(): Producer
  14. {
  15. if(is_null($this->producerContext)) {
  16. throw new ErrorException("Le contexte producteur n'est pas défini.");
  17. }
  18. return $this->producerContext;
  19. }
  20. public function getProducerContextId()
  21. {
  22. return $this->getProducerContext()->id;
  23. }
  24. }