1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the skeleton package. |
7
|
|
|
* |
8
|
|
|
* (c) Gennady Knyazkin <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Gennadyx\Skeleton; |
15
|
|
|
|
16
|
|
|
use Gennadyx\Skeleton\Action\ActionInterface; |
17
|
|
|
use Gennadyx\Skeleton\Action\ComposerInstall; |
18
|
|
|
use Gennadyx\Skeleton\Action\CreateSourceDirectories; |
19
|
|
|
use Gennadyx\Skeleton\Action\InstallFiles; |
20
|
|
|
use Gennadyx\Skeleton\Action\PhpstormProjectConfigure; |
21
|
|
|
use Gennadyx\Skeleton\Action\RemoveSkeletonDirectory; |
22
|
|
|
use Gennadyx\Skeleton\Action\SelfRemoving; |
23
|
|
|
use Gennadyx\Skeleton\Action\VarReplace; |
24
|
|
|
use MF\Collection\Immutable\Generic\ListCollection; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class ActionQueue |
28
|
|
|
* |
29
|
|
|
* @author Gennady Knyazkin <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class ActionQueue extends ListCollection |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* ActionQueue constructor. |
35
|
|
|
*/ |
36
|
5 |
|
public function __construct() |
37
|
|
|
{ |
38
|
5 |
|
parent::__construct(ActionInterface::class); |
39
|
5 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Create new actions priority queue |
43
|
|
|
* |
44
|
|
|
* @return ActionQueue|static |
45
|
|
|
*/ |
46
|
4 |
|
final public static function create(): ActionQueue |
47
|
|
|
{ |
48
|
4 |
|
return static::createGenericListFromArray( |
49
|
4 |
|
ActionInterface::class, |
50
|
4 |
|
static::sortByPriority(static::getActions()) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get actions list |
56
|
|
|
* |
57
|
|
|
* @return array|ActionInterface[] |
58
|
|
|
*/ |
59
|
5 |
|
protected static function getActions(): array |
60
|
|
|
{ |
61
|
|
|
return [ |
62
|
5 |
|
new CreateSourceDirectories(), |
63
|
5 |
|
new InstallFiles(), |
64
|
5 |
|
new PhpstormProjectConfigure(), |
65
|
5 |
|
new ComposerInstall(), |
66
|
5 |
|
new RemoveSkeletonDirectory(), |
67
|
5 |
|
new SelfRemoving(), |
68
|
5 |
|
new VarReplace(), |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Sort actions by priority |
74
|
|
|
* |
75
|
|
|
* @param array|ActionInterface[] $actions |
76
|
|
|
* |
77
|
|
|
* @return array|ActionInterface[] |
78
|
|
|
*/ |
79
|
|
|
protected static function sortByPriority(array $actions): array |
80
|
|
|
{ |
81
|
4 |
|
usort($actions, function (ActionInterface $a, ActionInterface $b) { |
82
|
4 |
|
return $a->getPriority() <=> $b->getPriority(); |
83
|
4 |
|
}); |
84
|
|
|
|
85
|
4 |
|
return array_values($actions); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|