ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilGlobalCacheSetupAgent.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3/* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
7
9{
13 protected $refinery;
14
15 public function __construct(
16 Refinery\Factory $refinery
17 ) {
18 $this->refinery = $refinery;
19 }
20
24 public function hasConfig() : bool
25 {
26 return true;
27 }
28
33 {
34 return $this->refinery->custom()->transformation(function ($data) {
35 $settings = new \ilGlobalCacheSettings();
36 if (
37 $data === null ||
38 !isset($data["components"]) ||
39 !$data["components"] ||
40 !isset($data["service"]) ||
41 $data["service"] === "none" ||
42 (
43 $data["service"] === "memcached" &&
44 (!isset($data["memcached_nodes"]) || count($data["memcached_nodes"]) === 0)
45 )
46 ) {
47 $settings->setActive(false);
48 } else {
49 $settings->setActive(true);
50 switch ($data["service"]) {
51 case "static":
52 $settings->setService(\ilGlobalCache::TYPE_STATIC);
53 break;
54 case "xcache":
55 $settings->setService(\ilGlobalCache::TYPE_XCACHE);
56 break;
57 case "memcached":
58 array_walk($data["memcached_nodes"], function (array $node) use ($settings) {
59 $settings->addMemcachedNode($this->getMemcachedServer($node));
60 });
61 $settings->setService(\ilGlobalCache::TYPE_MEMCACHED);
62 break;
63 case "apc":
64 $settings->setService(\ilGlobalCache::TYPE_APC);
65 break;
66 default:
67 throw new \InvalidArgumentException(
68 "Unknown caching service: '{$data["service"]}'"
69 );
70 }
71 $settings->resetActivatedComponents();
72 if ($data["components"] === "all") {
73 $settings->activateAll();
74 } else {
75 foreach ($data["components"] as $cmp => $active) {
76 if ($active) {
77 $settings->addActivatedComponent($cmp);
78 }
79 }
80 }
81 }
82
83 return $settings;
84 });
85 }
86
87 protected function getMemcachedServer(array $node) : ilMemcacheServer
88 {
89 $m = new ilMemcacheServer();
90 $m->setStatus(boolval($node["active"]) === true ? ilMemcacheServer::STATUS_ACTIVE : ilMemcacheServer::STATUS_INACTIVE);
91 $m->setHost((string) $node["host"]);
92 $m->setPort((int) $node["port"]);
93 $m->setWeight((int) $node["weight"]);
94
95 return $m;
96 }
97
101 public function getInstallObjective(Setup\Config $config = null) : Setup\Objective
102 {
104 }
105
109 public function getUpdateObjective(Setup\Config $config = null) : Setup\Objective
110 {
111 if ($config !== null) {
113 }
115 }
116
120 public function getBuildArtifactObjective() : Setup\Objective
121 {
123 }
124
128 public function getStatusObjective(Setup\Metrics\Storage $storage) : Setup\Objective
129 {
130 return new ilGlobalCacheMetricsCollectedObjective($storage);
131 }
132
136 public function getMigrations() : array
137 {
138 return [];
139 }
140
141 public function getNamedObjective(string $name, Setup\Config $config = null) : Setup\Objective
142 {
143 if ($name == "flushAll") {
145 }
146 throw new InvalidArgumentException(
147 "There is no named objective '$name'"
148 );
149 }
150}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
A non-objective, nothing to do to achieve it...
getUpdateObjective(Setup\Config $config=null)
getStatusObjective(Setup\Metrics\Storage $storage)
getInstallObjective(Setup\Config $config=null)
getNamedObjective(string $name, Setup\Config $config=null)
__construct(Refinery\Factory $refinery)
Class ilMemcacheServer.
A transformation is a function from one datatype to another.
A agent is some component that performs part of the setup process.
Definition: Agent.php:14
A configuration for the setup.
Definition: Config.php:11
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:15
if($format !==null) $name
Definition: metadata.php:230
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$data
Definition: storeScorm.php:23