-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBuildParser.php
More file actions
56 lines (50 loc) · 1.67 KB
/
BuildParser.php
File metadata and controls
56 lines (50 loc) · 1.67 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
48
49
50
51
52
53
54
55
56
<?php
namespace Orchestra\Workbench;
use Illuminate\Support\Collection;
/**
* @internal
*/
class BuildParser
{
/**
* List of disallowed commands.
*/
protected static array $disallowedCommands = [
'workbench:build',
'workbench:devtool',
'workbench:install',
];
/**
* Get Workbench build steps.
*
* @param array<int|string, array<string, mixed>|string> $config
* @return \Illuminate\Support\Collection<string, array<string, mixed>>
*/
public static function make(array $config): Collection
{
return (new Collection($config))
->map(static function (array|string $build) {
/** @var string $name */
$name = match (true) {
\is_array($build) => array_key_first($build),
\is_string($build) => $build,
};
/** @var array<string, mixed> $options */
$options = match (true) {
\is_array($build) => array_shift($build),
\is_string($build) => [],
};
return [
'name' => $name,
'options' => (new Collection($options))->mapWithKeys(static fn ($value, $key) => [$key => $value])->all(),
];
})->whereNotIn(
'name',
(new Collection(static::$disallowedCommands))
->transform(static fn ($command) => [$command, str_replace(':', '-', $command)])
->flatten(),
)->mapWithKeys(static fn (array $build) => [
$build['name'] => $build['options'],
]);
}
}