ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
Services.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Cache;
22 
30 
34 class Services
35 {
39  private array $containers = [];
40  private ?Adaptor $adaptor = null;
42 
43  public function __construct(
44  private ?Config $config = null,
45  ) {
46  if ($config === null) {
47  $this->config = new Config(Config::PHPSTATIC, true);
48  }
49  $this->adaptor_factory = new Factory();
50  }
51 
52  public function get(Request $for_container): Container
53  {
54  return $this->ensureContainer($for_container);
55  }
56 
57  private function ensureContainer(Request $for_container): Container
58  {
59  if (!array_key_exists($for_container->getContainerKey(), $this->containers)) {
60  $this->containers[$for_container->getContainerKey()] = $this->new($for_container);
61  }
62  return $this->containers[$for_container->getContainerKey()];
63  }
64 
65  private function new(Request $for_container): Container
66  {
67  if (!$this->config->isActivated()) {
68  return new VoidContainer($for_container);
69  }
70 
71  if (
72  $for_container->isForced() === false
73  && !in_array(Config::ALL, $this->config->getActivatedContainerKeys(), true)
74  && !in_array($for_container->getContainerKey(), $this->config->getActivatedContainerKeys(), true)
75  ) {
76  return new VoidContainer($for_container);
77  }
78 
79  return new ActiveContainer(
80  $for_container,
81  $this->getAdaptor(),
82  $this->config
83  );
84  }
85 
86  private function getAdaptor(): Adaptor
87  {
88  if ($this->adaptor === null) {
89  $this->adaptor = $this->adaptor_factory->getWithConfig($this->config);
90  }
91  return $this->adaptor;
92  }
93 
94  public function flushContainer(Request $container_request): void
95  {
96  $this->ensureContainer($container_request)->flush();
97  }
98 
99  public function flushAdapter(): void
100  {
101  $this->getAdaptor()->flush();
102  }
103 }
Factory $adaptor_factory
Definition: Services.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(private ?Config $config=null,)
Definition: Services.php:43
ensureContainer(Request $for_container)
Definition: Services.php:57
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
flushContainer(Request $container_request)
Definition: Services.php:94