CurrentStep.php
1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace WPML\Setup\Endpoint;
use WPML\Ajax\IHandler;
use WPML\Collect\Support\Collection;
use WPML\FP\Either;
use WPML\FP\Fns;
use WPML\FP\Logic;
use WPML\FP\Lst;
use WPML\FP\Obj;
use WPML\FP\Relation;
use WPML\Setup\Option;
class CurrentStep implements IHandler {
const STEP_TRANSLATION_SETTINGS = 'translationSettings';
const STEP_HIGH_COSTS_WARNING = 'highCostsWarning';
const STEPS = [
'languages',
'address',
'license',
'translation',
self::STEP_TRANSLATION_SETTINGS,
self::STEP_HIGH_COSTS_WARNING,
'pauseTranslateEverything',
'support',
'plugins',
'finished'
];
public function run( Collection $data ) {
$isValid = Logic::allPass( [
Lst::includes( Fns::__, self::STEPS ),
Logic::ifElse(
Relation::equals( 'languages' ),
Fns::identity(),
Fns::always( ! empty( Option::getTranslationLangs() ) )
),
] );
return Either::fromNullable( Obj::prop( 'currentStep', $data ) )
->filter( $isValid )
->map( [ Option::class, 'saveCurrentStep' ] );
}
}