From 1311e36b9da0aa2231d0cd7b899f8d31511e8328 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 11 Oct 2024 17:35:38 +0100 Subject: [PATCH 1/2] The `make:` commands don't need to register addon components anymore --- src/Console/Commands/MakeAction.php | 36 ------------------------- src/Console/Commands/MakeDictionary.php | 24 ----------------- src/Console/Commands/MakeFieldtype.php | 8 +----- src/Console/Commands/MakeFilter.php | 36 ------------------------- src/Console/Commands/MakeModifier.php | 34 ----------------------- src/Console/Commands/MakeScope.php | 34 ----------------------- src/Console/Commands/MakeTag.php | 34 ----------------------- src/Console/Commands/MakeWidget.php | 22 --------------- 8 files changed, 1 insertion(+), 227 deletions(-) diff --git a/src/Console/Commands/MakeAction.php b/src/Console/Commands/MakeAction.php index 1e83c98ff7..03d8892fb7 100644 --- a/src/Console/Commands/MakeAction.php +++ b/src/Console/Commands/MakeAction.php @@ -2,8 +2,6 @@ namespace Statamic\Console\Commands; -use Archetype\Facades\PHPFile; -use PhpParser\BuilderFactory; use Statamic\Console\RunsInPlease; class MakeAction extends GeneratorCommand @@ -37,38 +35,4 @@ class MakeAction extends GeneratorCommand * @var string */ protected $stub = 'action.php.stub'; - - /** - * Execute the console command. - * - * @return bool|null - */ - public function handle() - { - if (parent::handle() === false) { - return false; - } - - if ($this->argument('addon')) { - $this->updateServiceProvider(); - } - } - - /** - * Update the Service Provider to register the Action component. - */ - protected function updateServiceProvider() - { - $factory = new BuilderFactory(); - - $actionClassValue = $factory->classConstFetch('Actions\\'.$this->getNameInput(), 'class'); - - try { - PHPFile::load("addons/{$this->package}/src/ServiceProvider.php") - ->add()->protected()->property('actions', $actionClassValue) - ->save(); - } catch (\Exception $e) { - $this->comment("Don't forget to register the Action class in your addon's service provider."); - } - } } diff --git a/src/Console/Commands/MakeDictionary.php b/src/Console/Commands/MakeDictionary.php index f1a8618496..b1d2a1c281 100644 --- a/src/Console/Commands/MakeDictionary.php +++ b/src/Console/Commands/MakeDictionary.php @@ -2,8 +2,6 @@ namespace Statamic\Console\Commands; -use Archetype\Facades\PHPFile; -use PhpParser\BuilderFactory; use Statamic\Console\RunsInPlease; class MakeDictionary extends GeneratorCommand @@ -48,27 +46,5 @@ public function handle() if (parent::handle() === false) { return false; } - - if ($this->argument('addon')) { - $this->updateServiceProvider(); - } - } - - /** - * Update the Service Provider to register dictionary components. - */ - protected function updateServiceProvider() - { - $factory = new BuilderFactory(); - - $dictionaryClassValue = $factory->classConstFetch('Dictionaries\\'.$this->getNameInput(), 'class'); - - try { - PHPFile::load("addons/{$this->package}/src/ServiceProvider.php") - ->add()->protected()->property('dictionaries', $dictionaryClassValue) - ->save(); - } catch (\Exception $e) { - $this->comment("Don't forget to register the Dictionary class in your addon's service provider."); - } } } diff --git a/src/Console/Commands/MakeFieldtype.php b/src/Console/Commands/MakeFieldtype.php index 48a588ff75..b87b41d9d9 100644 --- a/src/Console/Commands/MakeFieldtype.php +++ b/src/Console/Commands/MakeFieldtype.php @@ -3,7 +3,6 @@ namespace Statamic\Console\Commands; use Archetype\Facades\PHPFile; -use PhpParser\BuilderFactory; use Statamic\Console\RunsInPlease; use Statamic\Support\Str; use Symfony\Component\Console\Input\InputOption; @@ -148,20 +147,15 @@ protected function wireUpAddonJs($addon) */ protected function updateServiceProvider() { - $factory = new BuilderFactory(); - - $fieldtypeClassValue = $factory->classConstFetch('Fieldtypes\\'.$this->getNameInput(), 'class'); - try { PHPFile::load("addons/{$this->package}/src/ServiceProvider.php") ->add()->protected()->property('vite', [ 'input' => ['resources/js/addon.js'], 'publicDirectory' => 'resources/dist', ]) - ->add()->protected()->property('fieldtypes', $fieldtypeClassValue) ->save(); } catch (\Exception $e) { - $this->comment("Don't forget to register the Fieldtype class and scripts in your addon's service provider."); + $this->comment("Don't forget to configure Vite in your addon's service provider."); } } diff --git a/src/Console/Commands/MakeFilter.php b/src/Console/Commands/MakeFilter.php index b753fa1b19..ce38f2e397 100644 --- a/src/Console/Commands/MakeFilter.php +++ b/src/Console/Commands/MakeFilter.php @@ -2,8 +2,6 @@ namespace Statamic\Console\Commands; -use Archetype\Facades\PHPFile; -use PhpParser\BuilderFactory; use Statamic\Console\RunsInPlease; class MakeFilter extends GeneratorCommand @@ -37,38 +35,4 @@ class MakeFilter extends GeneratorCommand * @var string */ protected $stub = 'filter.php.stub'; - - /** - * Execute the console command. - * - * @return bool|null - */ - public function handle() - { - if (parent::handle() === false) { - return false; - } - - if ($this->argument('addon')) { - $this->updateServiceProvider(); - } - } - - /** - * Update the Service Provider to register the Filter component. - */ - protected function updateServiceProvider() - { - $factory = new BuilderFactory(); - - $filterClassValue = $factory->classConstFetch('Filters\\'.$this->getNameInput(), 'class'); - - try { - PHPFile::load("addons/{$this->package}/src/ServiceProvider.php") - ->add()->protected()->property('filters', $filterClassValue) - ->save(); - } catch (\Exception $e) { - $this->comment("Don't forget to register the Filter class in your addon's service provider."); - } - } } diff --git a/src/Console/Commands/MakeModifier.php b/src/Console/Commands/MakeModifier.php index 96ef3e8a88..ee743fa419 100644 --- a/src/Console/Commands/MakeModifier.php +++ b/src/Console/Commands/MakeModifier.php @@ -37,38 +37,4 @@ class MakeModifier extends GeneratorCommand * @var string */ protected $stub = 'modifier.php.stub'; - - /** - * Execute the console command. - * - * @return bool|null - */ - public function handle() - { - if (parent::handle() === false) { - return false; - } - - if ($this->argument('addon')) { - $this->updateServiceProvider(); - } - } - - /** - * Update the Service Provider to register fieldtype components. - */ - protected function updateServiceProvider() - { - $factory = new BuilderFactory(); - - $modifierClassValue = $factory->classConstFetch('Modifiers\\'.$this->getNameInput(), 'class'); - - try { - PHPFile::load("addons/{$this->package}/src/ServiceProvider.php") - ->add()->protected()->property('modifiers', $modifierClassValue) - ->save(); - } catch (\Exception $e) { - $this->comment("Don't forget to register the Modifier class in your addon's service provider."); - } - } } diff --git a/src/Console/Commands/MakeScope.php b/src/Console/Commands/MakeScope.php index 3fc770ad59..2d67b5d4e4 100644 --- a/src/Console/Commands/MakeScope.php +++ b/src/Console/Commands/MakeScope.php @@ -37,38 +37,4 @@ class MakeScope extends GeneratorCommand * @var string */ protected $stub = 'scope.php.stub'; - - /** - * Execute the console command. - * - * @return bool|null - */ - public function handle() - { - if (parent::handle() === false) { - return false; - } - - if ($this->argument('addon')) { - $this->updateServiceProvider(); - } - } - - /** - * Update the Service Provider to register the scope component. - */ - protected function updateServiceProvider() - { - $factory = new BuilderFactory(); - - $scopeClassValue = $factory->classConstFetch('Scopes\\'.$this->getNameInput(), 'class'); - - try { - PHPFile::load("addons/{$this->package}/src/ServiceProvider.php") - ->add()->protected()->property('scopes', $scopeClassValue) - ->save(); - } catch (\Exception $e) { - $this->comment("Don't forget to register the Scope class in your addon's service provider."); - } - } } diff --git a/src/Console/Commands/MakeTag.php b/src/Console/Commands/MakeTag.php index 92bb893816..17d5b77419 100644 --- a/src/Console/Commands/MakeTag.php +++ b/src/Console/Commands/MakeTag.php @@ -39,40 +39,6 @@ class MakeTag extends GeneratorCommand */ protected $stub = 'tag.php.stub'; - /** - * Execute the console command. - * - * @return bool|null - */ - public function handle() - { - if (parent::handle() === false) { - return false; - } - - if ($this->argument('addon')) { - $this->updateServiceProvider(); - } - } - - /** - * Update the Service Provider to register the Tag component. - */ - protected function updateServiceProvider() - { - $factory = new BuilderFactory(); - - $tagsClassValue = $factory->classConstFetch('Tags\\'.$this->getNameInput(), 'class'); - - try { - PHPFile::load("addons/{$this->package}/src/ServiceProvider.php") - ->add()->protected()->property('tags', $tagsClassValue) - ->save(); - } catch (\Exception $e) { - $this->comment("Don't forget to register the Tag class in your addon's service provider."); - } - } - /** * Build the class with the given name. * diff --git a/src/Console/Commands/MakeWidget.php b/src/Console/Commands/MakeWidget.php index 65ef362760..5861c786a3 100644 --- a/src/Console/Commands/MakeWidget.php +++ b/src/Console/Commands/MakeWidget.php @@ -51,10 +51,6 @@ public function handle() } $this->generateWidgetView(); - - if ($this->argument('addon')) { - $this->updateServiceProvider(); - } } /** @@ -80,24 +76,6 @@ protected function generateWidgetView() ); } - /** - * Update the Service Provider to register the widget component. - */ - protected function updateServiceProvider() - { - $factory = new BuilderFactory(); - - $widgetClassValue = $factory->classConstFetch('Widgets\\'.$this->getNameInput(), 'class'); - - try { - PHPFile::load("addons/{$this->package}/src/ServiceProvider.php") - ->add()->protected()->property('widgets', $widgetClassValue) - ->save(); - } catch (\Exception $e) { - $this->info("Don't forget to register the Widget class in your addon's service provider."); - } - } - /** * Build the class with the given name. * From 535087de9895fa861615ab3890755cb1923b39f4 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 11 Oct 2024 17:54:14 +0100 Subject: [PATCH 2/2] Remove unused imports --- src/Console/Commands/MakeModifier.php | 2 -- src/Console/Commands/MakeScope.php | 2 -- src/Console/Commands/MakeTag.php | 2 -- src/Console/Commands/MakeWidget.php | 2 -- 4 files changed, 8 deletions(-) diff --git a/src/Console/Commands/MakeModifier.php b/src/Console/Commands/MakeModifier.php index ee743fa419..d8c1ccbcab 100644 --- a/src/Console/Commands/MakeModifier.php +++ b/src/Console/Commands/MakeModifier.php @@ -2,8 +2,6 @@ namespace Statamic\Console\Commands; -use Archetype\Facades\PHPFile; -use PhpParser\BuilderFactory; use Statamic\Console\RunsInPlease; class MakeModifier extends GeneratorCommand diff --git a/src/Console/Commands/MakeScope.php b/src/Console/Commands/MakeScope.php index 2d67b5d4e4..9361369ce7 100644 --- a/src/Console/Commands/MakeScope.php +++ b/src/Console/Commands/MakeScope.php @@ -2,8 +2,6 @@ namespace Statamic\Console\Commands; -use Archetype\Facades\PHPFile; -use PhpParser\BuilderFactory; use Statamic\Console\RunsInPlease; class MakeScope extends GeneratorCommand diff --git a/src/Console/Commands/MakeTag.php b/src/Console/Commands/MakeTag.php index 17d5b77419..7a4d9c65ad 100644 --- a/src/Console/Commands/MakeTag.php +++ b/src/Console/Commands/MakeTag.php @@ -2,8 +2,6 @@ namespace Statamic\Console\Commands; -use Archetype\Facades\PHPFile; -use PhpParser\BuilderFactory; use Statamic\Console\RunsInPlease; use Statamic\Support\Str; diff --git a/src/Console/Commands/MakeWidget.php b/src/Console/Commands/MakeWidget.php index 5861c786a3..54df3b7677 100644 --- a/src/Console/Commands/MakeWidget.php +++ b/src/Console/Commands/MakeWidget.php @@ -2,8 +2,6 @@ namespace Statamic\Console\Commands; -use Archetype\Facades\PHPFile; -use PhpParser\BuilderFactory; use Statamic\Console\RunsInPlease; use Statamic\Support\Str;