|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of dispositif/wikibot application |
|
4
|
|
|
* 2019 : Philippe M. <[email protected]> |
|
5
|
|
|
* For the full copyright and MIT license information, please view the LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace App\Domain\Models\Wiki; |
|
11
|
|
|
|
|
12
|
|
|
use App\Domain\Utils\ArrayProcessTrait; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @notused todo inutile ? |
|
16
|
|
|
* Class AbstractParametersObject |
|
17
|
|
|
*/ |
|
18
|
|
|
abstract class AbstractParametersObject |
|
19
|
|
|
{ |
|
20
|
|
|
use ArrayProcessTrait; |
|
21
|
|
|
|
|
22
|
|
|
protected $parametersValues; |
|
23
|
|
|
|
|
24
|
|
|
// public function generateSetterMethodList() |
|
25
|
|
|
// { |
|
26
|
|
|
// $list = ''; |
|
27
|
|
|
// foreach ($this->parametersByOrder as $name) { |
|
28
|
|
|
// $method = $this->setterMethodName($name); |
|
29
|
|
|
// $list .= 'private function '.$method."() { }\n"; |
|
30
|
|
|
// } |
|
31
|
|
|
// echo "<pre>$list</pre>"; |
|
32
|
|
|
// } |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Magic param setter. |
|
36
|
|
|
* |
|
37
|
|
|
* @param $name |
|
38
|
|
|
* |
|
39
|
|
|
* @return string |
|
40
|
88 |
|
*/ |
|
41
|
|
|
protected function setterMethodName(string $name): string |
|
42
|
88 |
|
{ |
|
43
|
88 |
|
$sanitizedName = str_replace([' ', 'à', 'é'], ['', 'a', 'e'], $name); |
|
44
|
|
|
$sanitizedName = preg_replace('#[^A-Za-z0-9]#', '', $sanitizedName); |
|
45
|
88 |
|
|
|
46
|
|
|
return 'set'.ucfirst($sanitizedName); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
|
public function toArray(): array |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->deleteEmptyValueArray($this->parametersValues); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Compare param/value datas. Empty value ignored. Params order ignored. |
|
60
|
|
|
* |
|
61
|
|
|
* @param AbstractParametersObject $object |
|
62
|
|
|
* |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
|
|
public function isParamValueEquals(self $object): bool |
|
66
|
|
|
{ |
|
67
|
|
|
$dat1 = $this->deleteEmptyValueArray($this->toArray()); |
|
68
|
|
|
$dat2 = $this->deleteEmptyValueArray($object->toArray()); |
|
69
|
|
|
if (count($dat1) !== count($dat2)) { |
|
70
|
|
|
return false; |
|
71
|
|
|
} |
|
72
|
|
|
foreach ($dat1 as $param => $value) { |
|
73
|
|
|
if (!isset($dat2[$param]) || $dat2[$param] !== $value) { |
|
74
|
|
|
return false; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return true; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|