|
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
|
|
|
|
|
11
|
|
|
namespace App\Application\OuvrageEdit\Validators; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
use App\Application\InfrastructurePorts\DbAdapterInterface; |
|
15
|
|
|
use App\Application\WikiBotConfig; |
|
16
|
|
|
use App\Application\WikiPageAction; |
|
17
|
|
|
use RuntimeException; |
|
18
|
|
|
|
|
19
|
|
|
class PageValidatorComposite implements ValidatorInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var ValidatorInterface[] */ |
|
22
|
|
|
protected $validators; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct( |
|
25
|
|
|
WikiBotConfig $botConfig, |
|
26
|
|
|
array $pageCitationCollection, |
|
27
|
|
|
DbAdapterInterface $db, |
|
28
|
|
|
WikiPageAction $wikiPageAction |
|
29
|
|
|
) |
|
30
|
|
|
{ |
|
31
|
|
|
$title = $pageCitationCollection[0]['page']; |
|
32
|
|
|
$this->validators = [ |
|
33
|
|
|
new ArticleValidForEditionValidator($title, $botConfig->getLogger(), $db, $wikiPageAction), |
|
34
|
|
|
new ArticleRestrictedValidator($title, $botConfig->getLogger(), $db, $wikiPageAction), |
|
35
|
|
|
new HumanDelayValidator($title, $botConfig), |
|
36
|
|
|
]; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function validate(): bool |
|
40
|
|
|
{ |
|
41
|
|
|
foreach ($this->validators as $validator) { |
|
42
|
|
|
if (!$validator instanceof ValidatorInterface) { |
|
43
|
|
|
throw new RuntimeException(get_class($validator) . ' must implement ValidatorInterface.'); |
|
44
|
|
|
} |
|
45
|
|
|
if ($validator->validate() === false) { |
|
46
|
|
|
return false; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return true; |
|
51
|
|
|
} |
|
52
|
|
|
} |