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