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

[make:event] Add command for making Event class #1574

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Ippey
Copy link

@Ippey Ippey commented Jun 20, 2024

I think adding "make:event" that makes Event class is good, although that is a small feature.
So, I wrote a simple make command.

php bin/console make:event


 The name of the event class (e.g. OrderPlacedEvent):
 > ItemCreatedEvent

 Field name (press enter to stop adding fields):
 > id

 Field type (e.g. string) [string]:
 > int

 Field visibility (public, protected, private) [public]:
  [0] public
  [1] private
  [2] protected
 > public

 Can this field be null (nullable) (yes/no) [no]:
 > no

 Field name (press enter to stop adding fields):
 > 

It makes bellow

<?php

namespace App\Event;

use Symfony\Contracts\EventDispatcher\Event;

final class ItemCreatedEvent extends Event
{
    public function __construct(
        public readonly int $id,
    ) {
    }
}

@94noni
Copy link
Contributor

94noni commented Jun 26, 2024

i thinks its a good idea, would definitely use it if it lands in the bundle

perhaps we can imagine a step forward with adding the command asking the Event "data" in an asking interactive question way? like some other existing makers commands

bin/console make:event
ItemCreatedEvent
would you like to add some event's properties? yes (continue) / no (exit and generate code)
Property name?
identifier
Property type?
integer
Property visibility?
public

<?php

namespace App\Event;

use Symfony\Contracts\EventDispatcher\Event;

final class ItemCreatedEvent extends Event
{
    public function __construct(public int $identifier)
    {
    }
}

wdyt?

@Ippey
Copy link
Author

Ippey commented Jun 28, 2024

@94noni Thank you. That's great!
I'll try it.

@Ippey
Copy link
Author

Ippey commented Jun 30, 2024

Updated. It can make an event class with properties interactively.
We can set bellow:

  • name
  • type
  • visibility
  • nullable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants