Skip to content

Commit c38dc31

Browse files
committed
Use objects for proper declaration; add description as helper
1 parent 29abd86 commit c38dc31

File tree

5 files changed

+187
-15
lines changed

5 files changed

+187
-15
lines changed

src/Config.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Glpi\Application\Environment;
3737
use Glpi\Application\View\TemplateRenderer;
3838
use Glpi\Cache\CacheManager;
39+
use Glpi\Config\ProxyExclusion;
3940
use Glpi\Dashboard\Grid;
4041
use Glpi\Event;
4142
use Glpi\Helpdesk\HelpdeskTranslation;
@@ -874,20 +875,39 @@ public function showSystemInformations()
874875
return;
875876
}
876877

878+
/** @var \Glpi\Config\ProxyExclusions $proxy_exclusions */
879+
$proxy_exclusions = $CFG_GLPI['possible_proxy_exclusions'];
880+
$proxy_exclusions->addExclusions([
881+
new ProxyExclusion(
882+
Agent::class,
883+
Agent::getTypeName()
884+
),
885+
new ProxyExclusion(
886+
GLPINetwork::class,
887+
GLPINetwork::getTypeName(),
888+
__('GLPI network related calls (marketplace, versions check, telemetry, ...')
889+
),
890+
new ProxyExclusion(
891+
RSSFeed::class,
892+
RSSFeed::getTypeName()
893+
),
894+
new ProxyExclusion(
895+
Planning::class,
896+
Planning::getTypeName()
897+
),
898+
new ProxyExclusion(
899+
OauthConfig::class,
900+
__('SMTP OAuth Authentication')
901+
),
902+
new ProxyExclusion(
903+
Webhook::class,
904+
Webhook::getTypeName()
905+
),
906+
]);
877907
TemplateRenderer::getInstance()->display('pages/setup/general/systeminfo_form.html.twig', [
878908
'config' => $CFG_GLPI,
879909
'canedit' => static::canUpdate(),
880-
'possible_proxy_exclusions' => array_merge(
881-
[
882-
Agent::class => Agent::getTypeName(),
883-
GLPINetwork::class => GLPINetwork::getTypeName(),
884-
RSSFeed::class => RSSFeed::getTypeName(),
885-
Planning::class => Planning::getTypeName(),
886-
OauthConfig::class => __('SMTP OAuth Authentication'),
887-
Webhook::class => Webhook::getTypeName(),
888-
],
889-
$CFG_GLPI['possible_proxy_exclusions']
890-
),
910+
'possible_proxy_exclusions' => $proxy_exclusions,
891911
]);
892912
self::showSystemInfoTable();
893913
}

src/Glpi/Config/ProxyExclusion.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/**
4+
* ---------------------------------------------------------------------
5+
*
6+
* GLPI - Gestionnaire Libre de Parc Informatique
7+
*
8+
* http://glpi-project.org
9+
*
10+
* @copyright 2015-2025 Teclib' and contributors.
11+
* @copyright 2003-2014 by the INDEPNET Development Team.
12+
* @licence https://www.gnu.org/licenses/gpl-3.0.html
13+
*
14+
* ---------------------------------------------------------------------
15+
*
16+
* LICENSE
17+
*
18+
* This file is part of GLPI.
19+
*
20+
* This program is free software: you can redistribute it and/or modify
21+
* it under the terms of the GNU General Public License as published by
22+
* the Free Software Foundation, either version 3 of the License, or
23+
* (at your option) any later version.
24+
*
25+
* This program is distributed in the hope that it will be useful,
26+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+
* GNU General Public License for more details.
29+
*
30+
* You should have received a copy of the GNU General Public License
31+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
32+
*
33+
* ---------------------------------------------------------------------
34+
*/
35+
36+
namespace Glpi\Config;
37+
38+
final readonly class ProxyExclusion
39+
{
40+
public function __construct(
41+
private string $classname,
42+
private string $label,
43+
private string $description = ''
44+
) {
45+
//
46+
}
47+
48+
public function getClassname(): string
49+
{
50+
return $this->classname;
51+
}
52+
53+
public function getLabel(): string
54+
{
55+
return $this->label;
56+
}
57+
58+
public function getDescription(): string
59+
{
60+
if ($this->description !== '') {
61+
return sprintf(__('%s: %s'), $this->label, $this->description);
62+
}
63+
return $this->label;
64+
}
65+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
/**
4+
* ---------------------------------------------------------------------
5+
*
6+
* GLPI - Gestionnaire Libre de Parc Informatique
7+
*
8+
* http://glpi-project.org
9+
*
10+
* @copyright 2015-2025 Teclib' and contributors.
11+
* @copyright 2003-2014 by the INDEPNET Development Team.
12+
* @licence https://www.gnu.org/licenses/gpl-3.0.html
13+
*
14+
* ---------------------------------------------------------------------
15+
*
16+
* LICENSE
17+
*
18+
* This file is part of GLPI.
19+
*
20+
* This program is free software: you can redistribute it and/or modify
21+
* it under the terms of the GNU General Public License as published by
22+
* the Free Software Foundation, either version 3 of the License, or
23+
* (at your option) any later version.
24+
*
25+
* This program is distributed in the hope that it will be useful,
26+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+
* GNU General Public License for more details.
29+
*
30+
* You should have received a copy of the GNU General Public License
31+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
32+
*
33+
* ---------------------------------------------------------------------
34+
*/
35+
36+
namespace Glpi\Config;
37+
38+
use CommonGLPI;
39+
40+
final class ProxyExclusions
41+
{
42+
/** @var array<class-string<CommonGLPI>, ProxyExclusion> */
43+
private array $exclusions = [];
44+
45+
public function addExclusion(ProxyExclusion $exclusion): self
46+
{
47+
$this->exclusions[$exclusion->getClassname()] = $exclusion;
48+
return $this;
49+
}
50+
51+
/** @param array<ProxyExclusion> $exclusions */
52+
public function addExclusions(array $exclusions): self
53+
{
54+
foreach ($exclusions as $exclusion) {
55+
$this->addExclusion($exclusion);
56+
}
57+
return $this;
58+
}
59+
60+
/**
61+
* @return array<class-string<CommonGLPI>, ProxyExclusion>
62+
*/
63+
public function getExclusions(): array
64+
{
65+
return $this->exclusions;
66+
}
67+
68+
public function getDropDownValues(): array
69+
{
70+
$values = [];
71+
foreach ($this->exclusions as $exclusion) {
72+
$values[$exclusion->getClassname()] = $exclusion->getLabel();
73+
}
74+
return $values;
75+
}
76+
77+
public function getDescriptions(): string
78+
{
79+
$descriptions = __('Objects that should not use proxy configuration:');
80+
foreach ($this->exclusions as $exclusion) {
81+
$descriptions .= '<br/>- ' . $exclusion->getDescription();
82+
}
83+
return $descriptions;
84+
}
85+
}

src/autoload/CFG_GLPI.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,4 +646,5 @@
646646
$CFG_GLPI['process_types'] = [Computer::class];
647647
$CFG_GLPI['environment_types'] = [Computer::class];
648648

649-
$CFG_GLPI['possible_proxy_exclusions'] = [];
649+
650+
$CFG_GLPI['possible_proxy_exclusions'] = new \Glpi\Config\ProxyExclusions();

templates/pages/setup/general/systeminfo_form.html.twig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@
6868
{{ fields.dropdownArrayField(
6969
'proxy_exclusions',
7070
null,
71-
possible_proxy_exclusions,
71+
possible_proxy_exclusions.getDropDownValues(),
7272
__('Proxy exclusions'),
7373
{
7474
multiple: true,
7575
size: 3,
76-
values: config['proxy_exclusions']
77-
}
76+
values: config['proxy_exclusions'],
77+
helper: possible_proxy_exclusions.getDescriptions()
78+
},
7879
) }}
7980

8081
{{ fields.smallTitle(__('Telemetry data')) }}

0 commit comments

Comments
 (0)