-
-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathWireElementsModalUpgrade.php
More file actions
75 lines (68 loc) · 3.4 KB
/
WireElementsModalUpgrade.php
File metadata and controls
75 lines (68 loc) · 3.4 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
<?php
namespace LivewireUI\Modal;
use Livewire\Features\SupportConsoleCommands\Commands\Upgrade\UpgradeStep;
use Livewire\Features\SupportConsoleCommands\Commands\UpgradeCommand;
class WireElementsModalUpgrade extends UpgradeStep
{
public function handle(UpgradeCommand $console, \Closure $next)
{
$this->interactiveReplacement(
console: $console,
title: 'The $dispatch helper expects named arguments.',
before: '$dispatch(\'openModal\', \'component-name\', {user: 1})',
after: '$dispatch(\'openModal\', {modalComponent: \'component-name\', arguments: {user: 1}})',
pattern: '/\$(?:dispatch|emit)\(\'openModal\'(?:,\s?)([^,|\)]*)(?:,\s?)?((?:(?:.|\s)*?).*)\)/',
replacement: function($matches) {
$component = $matches[1];
$arguments = $matches[2];
if (empty($arguments)) {
return "\$dispatch('openModal', { modalComponent: $component })";
}
return "\$dispatch('openModal', { modalComponent: $component, arguments: $arguments })";
},
directories: 'resources'
);
$this->interactiveReplacement(
console: $console,
title: '$this->dispatch now expects named arguments.',
before: '$this->dispatch(\'openModal\', \'component-name\', [\'user\' => 1])',
after: '$this->dispatch(\'openModal\', modalComponent: \'component-name\', arguments: [\'user\' => 1])',
pattern: '/\$this->(?:dispatch|emit)\(\'openModal\'(?:,\s?)([^,|\)]*)(?:,\s?)?((?:(?:.|\s)*?).*)\)/',
replacement: function($matches) {
$component = $matches[1];
$arguments = $matches[2];
if (empty($arguments)) {
return "\$this->dispatch('openModal', modalComponent: $component)";
}
return "\$this->dispatch('openModal', modalComponent: $component, arguments: $arguments)";
},
directories: ['app', 'tests']
);
$this->interactiveReplacement(
console: $console,
title: 'The Livewire.dispatch helper expects named arguments.',
before: 'Livewire.dispatch(\'openModal\', \'component-name\', {user: 1})',
after: 'Livewire.dispatch(\'openModal\', {component: \'component-name\', arguments: {user: 1}})',
pattern: '/Livewire\.(?:dispatch|emit)\(\'openModal\'(?:,\s?)([^,|\)]*)(?:,\s?)?((?:(?:.|\s)*?).*)\)/',
replacement: function($matches) {
$component = $matches[1];
$arguments = $matches[2];
if (empty($arguments)) {
return "Livewire.dispatch('openModal', { modalComponent: $component })";
}
return "Livewire.dispatch('openModal', {component: $component, arguments: $arguments })";
},
directories: 'resources'
);
$this->interactiveReplacement(
console: $console,
title: 'The modal directive has been changed.',
before: '@livewire(\'livewire-ui-modal\')',
after: '@livewire(\'wire-elements-modal\')',
pattern: '/@livewire\([\'|"]livewire-ui-modal[\'|"]\)/',
replacement: '@livewire(\'wire-elements-modal\')',
directories: 'resources/views'
);
return $next($console);
}
}