-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17c2d39
commit 1fbbfdc
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Windwalker\Core\Generator\SubCommand; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Windwalker\Console\CommandWrapper; | ||
use Windwalker\Console\IOInterface; | ||
|
||
/** | ||
* The GenEnumSubCommand class. | ||
*/ | ||
#[CommandWrapper( | ||
description: 'Generate Windwalker event subscriber.' | ||
)] | ||
class SubscriberSubCommand extends AbstractGeneratorSubCommand | ||
{ | ||
protected string $defaultNamespace = 'Subscriber'; | ||
|
||
protected string $defaultDir = 'Subscriber'; | ||
|
||
protected bool $requireDest = false; | ||
|
||
/** | ||
* configure | ||
* | ||
* @param Command $command | ||
* | ||
* @return void | ||
*/ | ||
public function configure(Command $command): void | ||
{ | ||
parent::configure($command); | ||
} | ||
|
||
/** | ||
* Executes the current command. | ||
* | ||
* @param IOInterface $io | ||
* | ||
* @return int Return 0 is success, 1-255 is failure. | ||
*/ | ||
public function execute(IOInterface $io): int | ||
{ | ||
[, $name] = $this->getNameParts($io); | ||
$force = $io->getOption('force'); | ||
|
||
if (!$name) { | ||
$io->errorStyle()->error('No subscriber name'); | ||
|
||
return 255; | ||
} | ||
|
||
$this->codeGenerator->from($this->getViewPath('subscriber/*.tpl')) | ||
->replaceTo( | ||
$this->getDestPath($io), | ||
[ | ||
'name' => $name, | ||
'ns' => $this->getNamespace($io), | ||
], | ||
$force | ||
); | ||
|
||
return 0; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
views/code/subscriber/{% pascal($name) %}Subscriber.php.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% $phpOpen %} | ||
|
||
declare(strict_types=1); | ||
|
||
namespace {% $ns %}; | ||
|
||
use Windwalker\Event\Attributes\EventSubscriber; | ||
use Windwalker\Event\Attributes\ListenTo; | ||
|
||
#[EventSubscriber] | ||
class {% pascal($name) %}Subscriber | ||
{ | ||
#[ListenTo(FooEvent::class)] | ||
public function foo($event): void | ||
{ | ||
// | ||
} | ||
} |