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

Use getChildTypes method to allow method overriding #53

Closed
wants to merge 1 commit into from

Conversation

BertvanHoekelen
Copy link
Contributor

We define our child types based on values from phpenum, however all constants are marked as private and cannot be used outside of the enum (this enforces us the use the method instead of the private constant).

But expressions are not allowed as field default values, so we would like to override the getChildTypes method.

e.g.

...

class Vehicle extends Model
{
    use HasChildren;

   protected $childTypes = [
        EnumVehicle::CAR => Car::class
   ];
}

Becomes in our case
e.g.

...

class Vehicle extends Model
{
    use HasChildren;

    public function getChildTypes(): array
    {
          return [
              EnumVehicle::CAR()->getValue() => Car::class
          ];
    }
}

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.

1 participant