Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ProducerContextTrait.php 839B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace domain\_;
  3. use domain\Producer\Producer\Producer;
  4. use yii\base\ErrorException;
  5. trait ProducerContextTrait
  6. {
  7. protected ?Producer $producerContext = null;
  8. public function setProducerContext(Producer $producer = null): self
  9. {
  10. $this->producerContext = $producer;
  11. return $this;
  12. }
  13. public function getProducerContext(bool $throwExceptionIfNull = true): ?Producer
  14. {
  15. if($throwExceptionIfNull && 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. public function isOutOfProducerContext(): bool
  25. {
  26. return !$this->producerContext;
  27. }
  28. }