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

Handle enum last_state values #68

Closed
leonelngande opened this issue Nov 16, 2023 · 2 comments
Closed

Handle enum last_state values #68

leonelngande opened this issue Nov 16, 2023 · 2 comments

Comments

@leonelngande
Copy link

Hello. With Laravel now supporting attribute casting I do this with my last_state property:

    protected $casts = [
        'last_state' => \App\Enums\MoneyTransferState::class,
    ];

Where MoneyTransferState is a string backed enum. This however creates a problem given the getState() in SM\StateMachine's return value is expected to be a string.

public function getState(): string
    {
        $accessor = new PropertyAccessor();
        return $accessor->getValue($this->object, $this->config['property_path']);
    }

Can i make a pull request with this modification?

    public function getState(): string
    {
        $accessor = new PropertyAccessor();
        $state = $accessor->getValue($this->object, $this->config['property_path']);
        if ($state instanceof UnitEnum) {
            return $state->value;
        }
        return $state;
    }

Thanks

@sebdesign
Copy link
Owner

I have fixed this in the latest release. Thanks!

@leonelngande
Copy link
Author

Oh, thanks!

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

No branches or pull requests

2 participants