vendor/hofff/contao-consent-bridge/src/Manager/BridgeConsentToolManager.php line 49

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Hofff\Contao\Consent\Bridge\Manager;
  4. use Contao\LayoutModel;
  5. use Contao\PageModel;
  6. use Hofff\Contao\Consent\Bridge\Bridge;
  7. use Hofff\Contao\Consent\Bridge\ConsentTool;
  8. use Hofff\Contao\Consent\Bridge\ConsentToolManager;
  9. use InvalidArgumentException;
  10. use function sprintf;
  11. final class BridgeConsentToolManager implements ConsentToolManager
  12. {
  13.     /** @var Bridge */
  14.     private $bridge;
  15.     /** @var ConsentTool|null */
  16.     private $activeConsentTool;
  17.     public function __construct(Bridge $bridge)
  18.     {
  19.         $this->bridge $bridge;
  20.     }
  21.     /** @return ConsentTool[] */
  22.     public function consentTools(): array
  23.     {
  24.         return $this->bridge->consentTools();
  25.     }
  26.     public function has(string $name): bool
  27.     {
  28.         return isset($this->consentTools()[$name]);
  29.     }
  30.     public function get(string $name): ConsentTool
  31.     {
  32.         if (! $this->has($name)) {
  33.             throw new InvalidArgumentException(sprintf('Consent tool "%s" is not known'$name));
  34.         }
  35.         return $this->consentTools()[$name];
  36.     }
  37.     public function activate(
  38.         string $name,
  39.         PageModel $rootPageModel,
  40.         ?PageModel $pageModel null,
  41.         ?LayoutModel $layoutModel null
  42.     ): bool {
  43.         $consentTool $this->get($name);
  44.         if ($consentTool->activate($rootPageModel$pageModel$layoutModel)) {
  45.             $this->activeConsentTool $consentTool;
  46.             return true;
  47.         }
  48.         return false;
  49.     }
  50.     public function activeConsentTool(): ?ConsentTool
  51.     {
  52.         return $this->activeConsentTool;
  53.     }
  54. }