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.
|
- <?php
-
- namespace domain\_;
-
- use domain\Producer\Producer\Producer;
- use yii\base\ErrorException;
-
- trait ProducerContextTrait
- {
- protected ?Producer $producerContext = null;
-
- public function setProducerContext(Producer $producer = null): self
- {
- $this->producerContext = $producer;
-
- return $this;
- }
-
- public function getProducerContext(bool $throwExceptionIfNull = true): ?Producer
- {
- if($throwExceptionIfNull && is_null($this->producerContext)) {
- throw new ErrorException("Le contexte producteur n'est pas défini.");
- }
-
- return $this->producerContext;
- }
-
- public function getProducerContextId()
- {
- return $this->getProducerContext()->id;
- }
-
- public function isOutOfProducerContext(): bool
- {
- return !$this->producerContext;
- }
- }
|