Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] make: commands dont need to register addon components #10942

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading