|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of dispositif/wikibot application (@github) |
|
4
|
|
|
* 2019-2023 © Philippe M./Irønie <[email protected]> |
|
5
|
|
|
* For the full copyright and MIT license information, view the license file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace App\Domain\WikiOptimizer; |
|
11
|
|
|
|
|
12
|
|
|
use App\Domain\InfrastructurePorts\PageListInterface; |
|
13
|
|
|
use App\Domain\Models\Wiki\AbstractWikiTemplate; |
|
14
|
|
|
use App\Domain\SummaryLogTrait; |
|
15
|
|
|
use Exception; |
|
16
|
|
|
use Psr\Log\LoggerInterface; |
|
17
|
|
|
use Psr\Log\NullLogger; |
|
18
|
|
|
|
|
19
|
|
|
abstract class AbstractTemplateOptimizer implements TemplateOptimizerInterface |
|
20
|
|
|
{ |
|
21
|
|
|
use SummaryLogTrait; |
|
22
|
|
|
|
|
23
|
|
|
protected $originTemplate; |
|
24
|
|
|
|
|
25
|
|
|
protected $wikiPageTitle; |
|
26
|
|
|
|
|
27
|
|
|
protected $optiTemplate; |
|
28
|
|
|
|
|
29
|
|
|
protected $notCosmetic = false; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var LoggerInterface|NullLogger |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $log; |
|
35
|
|
|
/** |
|
36
|
|
|
* @var PageListInterface|null |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $pageListManager; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* todo Refac add doTasks() in constructor if no optional method needed between doTasks() and getOptiTemplate() |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct( |
|
44
|
|
|
AbstractWikiTemplate $template, |
|
45
|
|
|
?string $wikiPageTitle = null, |
|
46
|
|
|
?LoggerInterface $log = null, |
|
47
|
|
|
?PageListInterface $pageListManager = null |
|
48
|
|
|
) { |
|
49
|
|
|
$this->originTemplate = $template; |
|
50
|
|
|
$this->optiTemplate = clone $template; |
|
51
|
|
|
$this->wikiPageTitle = ($wikiPageTitle) ?? null; |
|
52
|
|
|
$this->log = $log ?? new NullLogger(); |
|
53
|
|
|
$this->pageListManager = $pageListManager; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getOptiTemplate(): AbstractWikiTemplate |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->optiTemplate; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return bool |
|
63
|
|
|
*/ |
|
64
|
|
|
public function isNotCosmetic(): bool |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->notCosmetic; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* TODO : return "" instead of null ? |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function getParam(string $name): ?string |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->optiTemplate->getParam($name); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
protected function hasParamValue(string $name): bool |
|
78
|
|
|
{ |
|
79
|
|
|
return !empty($this->optiTemplate->getParam($name)); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
protected function unsetParam($name) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->optiTemplate->unsetParam($name); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param $name |
|
89
|
|
|
* @param $value |
|
90
|
|
|
* |
|
91
|
|
|
* @throws Exception |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function setParam($name, $value) |
|
94
|
|
|
{ |
|
95
|
|
|
// todo : overwrite setParam() ? |
|
96
|
|
|
if (!empty($value) || $this->optiTemplate->getParam($name)) { |
|
97
|
|
|
$this->optiTemplate->setParam($name, $value); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|