Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php declare(strict_types = 1);
- namespace NameSpace\Units\Core\Registers\Traits;
- use NameSpace\Support\Exceptions\AppException;
- use NameSpace\Units\Core\Registers\Interfaces\Registrable;
- trait EnforceEnvRegistration
- {
- protected bool $hasRegistered = false;
- protected bool $hasEnvSet = false;
- /**
- * add
- *
- * @param mixed $registry
- * @return self
- */
- public function add(Registrable $registry): self
- {
- $this->hasRegistered = true;
- parent::add($registry);
- }
- /**
- * env
- *
- * @param mixed $env
- * @return void
- */
- public function env(string $env): void
- {
- $this->hasEnvSet = true;
- parent::env($env);
- }
- /**
- * checkEnvEnforcement
- *
- * @return void
- */
- public function checkEnvEnforcement(): void
- {
- if (!$this->hasRegistered && $this->hasEnvSet)
- {
- throw new AppException('please call ->env() after calling ->add() method from the registers');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement