diff --git a/src/WireElementsModalUpgrade.php b/src/WireElementsModalUpgrade.php index 3b0ca7b..1af7cc3 100644 --- a/src/WireElementsModalUpgrade.php +++ b/src/WireElementsModalUpgrade.php @@ -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' );