Skip to content

Commit

Permalink
[5.x] make: commands dont need to register addon components (#10942)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored Oct 14, 2024
1 parent 9a966ea commit fa1a6a9
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 235 deletions.
36 changes: 0 additions & 36 deletions src/Console/Commands/MakeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Statamic\Console\Commands;

use Archetype\Facades\PHPFile;
use PhpParser\BuilderFactory;
use Statamic\Console\RunsInPlease;

class MakeAction extends GeneratorCommand
Expand Down Expand Up @@ -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.");
}
}
}
24 changes: 0 additions & 24 deletions src/Console/Commands/MakeDictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Statamic\Console\Commands;

use Archetype\Facades\PHPFile;
use PhpParser\BuilderFactory;
use Statamic\Console\RunsInPlease;

class MakeDictionary extends GeneratorCommand
Expand Down Expand Up @@ -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.");
}
}
}
8 changes: 1 addition & 7 deletions src/Console/Commands/MakeFieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
}
}

Expand Down
36 changes: 0 additions & 36 deletions src/Console/Commands/MakeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Statamic\Console\Commands;

use Archetype\Facades\PHPFile;
use PhpParser\BuilderFactory;
use Statamic\Console\RunsInPlease;

class MakeFilter extends GeneratorCommand
Expand Down Expand Up @@ -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.");
}
}
}
36 changes: 0 additions & 36 deletions src/Console/Commands/MakeModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Statamic\Console\Commands;

use Archetype\Facades\PHPFile;
use PhpParser\BuilderFactory;
use Statamic\Console\RunsInPlease;

class MakeModifier extends GeneratorCommand
Expand Down Expand Up @@ -37,38 +35,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.");
}
}
}
36 changes: 0 additions & 36 deletions src/Console/Commands/MakeScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Statamic\Console\Commands;

use Archetype\Facades\PHPFile;
use PhpParser\BuilderFactory;
use Statamic\Console\RunsInPlease;

class MakeScope extends GeneratorCommand
Expand Down Expand Up @@ -37,38 +35,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.");
}
}
}
36 changes: 0 additions & 36 deletions src/Console/Commands/MakeTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Statamic\Console\Commands;

use Archetype\Facades\PHPFile;
use PhpParser\BuilderFactory;
use Statamic\Console\RunsInPlease;
use Statamic\Support\Str;

Expand Down Expand Up @@ -39,40 +37,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.
*
Expand Down
24 changes: 0 additions & 24 deletions src/Console/Commands/MakeWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Statamic\Console\Commands;

use Archetype\Facades\PHPFile;
use PhpParser\BuilderFactory;
use Statamic\Console\RunsInPlease;
use Statamic\Support\Str;

Expand Down Expand Up @@ -51,10 +49,6 @@ public function handle()
}

$this->generateWidgetView();

if ($this->argument('addon')) {
$this->updateServiceProvider();
}
}

/**
Expand All @@ -80,24 +74,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.
*
Expand Down

0 comments on commit fa1a6a9

Please sign in to comment.