-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModuleMigrator.php
More file actions
89 lines (74 loc) · 2.85 KB
/
ModuleMigrator.php
File metadata and controls
89 lines (74 loc) · 2.85 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace Softspring\CmsBundle\Utils;
class ModuleMigrator
{
public static function migrate(array $migrationScripts, $moduleData, $toRevision): array
{
foreach ($migrationScripts as $migrationScript) {
$moduleData = (include $migrationScript)($moduleData, (int) ($moduleData['_revision'] ?? 1), $toRevision);
}
$moduleData['_revision'] = $toRevision;
return $moduleData;
}
public static function routeToSymfonyRoute(?string $oldRouteValue): array
{
if (is_string($oldRouteValue) && '' !== $oldRouteValue && 'route___' !== substr($oldRouteValue, 0, 8)) {
error_log("Bad-formed '$oldRouteValue' route to migrate, has been set to null.");
$oldRouteValue = null;
}
return [
// migrate from route___<route_name> format
'route_name' => $oldRouteValue ? substr($oldRouteValue, 8) : null,
'route_params' => [],
];
}
public static function symfonyRouteToLink(?array $symfonyRoute): array
{
return [
'type' => !empty($symfonyRoute) ? 'route' : 'url',
'route_name' => !empty($symfonyRoute) ? $symfonyRoute['route_name'] : null,
'route_params' => !empty($symfonyRoute) ? $symfonyRoute['route_params'] : null,
'url' => !empty($symfonyRoute) ? null : '',
'anchor' => null,
'target' => '_self',
'custom_target' => null,
];
}
public static function classToSpacing(string $class): array
{
$spacing = [
'marginTop' => '',
'marginEnd' => '',
'marginBottom' => '',
'marginStart' => '',
'paddingTop' => '',
'paddingEnd' => '',
'paddingBottom' => '',
'paddingStart' => '',
];
preg_match_all('/([mp][tbesxy]?\-[012345])/', $class, $matches);
foreach ($matches[0] as $match) {
$class = str_replace($match, '', $class);
$match = explode('-', $match);
$marginOrPadding = substr($match[0], 0, 1);
$p = substr($match[0], 1, 1);
$amount = $match[1];
$mp = ['m' => 'margin', 'p' => 'padding'][$marginOrPadding];
$positions = [
't' => ['Top'],
'b' => ['Bottom'],
'e' => ['End'],
's' => ['Start'],
'' => ['Top', 'End', 'Bottom', 'Start'],
'y' => ['Top', 'Bottom'],
'x' => ['End', 'Start'],
][$p];
foreach ($positions as $position) {
$p = strtolower(substr($position, 0, 1));
$spacing["$mp$position"] = "$marginOrPadding$p-$amount";
}
}
$class = implode(' ', array_filter(explode(' ', $class)));
return [$class, $spacing];
}
}