Skip to content

Commit

Permalink
[V2] Upgrade pattern improvements (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
thermiteplasma authored Aug 16, 2023
1 parent 5f24104 commit beee4d2
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/WireElementsModalUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,48 @@ public function handle(UpgradeCommand $console, \Closure $next)
title: 'The $dispatch helper expects named arguments.',
before: '$dispatch(\'openModal\', \'component-name\', {user: 1})',
after: '$dispatch(\'openModal\', {component: \'component-name\', arguments: {user: 1}})',
pattern: '/\$(?:dispatch|emit)\(\'openModal\', \'([^\']+)\'(?:, (\{[^}]+\}|@js\(\[[^\]]+\]\)))?\)/',
pattern: '/\$(?:dispatch|emit)\(\'openModal\'(?:,\s?)([^,|\)]*)(?:,\s?)?((?:(?:.|\s)*?).*)\)/',
replacement: function($matches) {
$component = $matches[1];
$params = isset($matches[2]) ? ', arguments: ' . $matches[2] : '';
return "\$dispatch('openModal', {component: '$component'$params})";
$arguments = $matches[2];
if (empty($arguments)) {
return "\$dispatch('openModal', { component: $component })";
}
return "\$dispatch('openModal', { component: $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\', {component: \'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', { component: $component })";
}
return "\$this->dispatch('openModal', { component: $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\', \'([^\']+)\'(?:, (\{[^}]+\}|@js\(\[[^\]]+\]\)))?\)/',
pattern: '/Livewire\.(?:dispatch|emit)\(\'openModal\'(?:,\s?)([^,|\)]*)(?:,\s?)?((?:(?:.|\s)*?).*)\)/',
replacement: function($matches) {
$component = $matches[1];
$params = isset($matches[2]) ? ', arguments: ' . $matches[2] : '';
return "Livewire.dispatch('openModal', {component: '$component'$params})";
$arguments = $matches[2];
if (empty($arguments)) {
return "Livewire.dispatch('openModal', { component: $component })";
}
return "Livewire.dispatch('openModal', {component: $component, arguments: $arguments })";
},
directories: 'resources'
);
Expand Down

0 comments on commit beee4d2

Please sign in to comment.