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

feat: add custom casts #227

Open
wants to merge 1 commit into
base: feat/add-enum-casts
Choose a base branch
from

Conversation

edipoReboucas
Copy link

@edipoReboucas edipoReboucas commented Oct 20, 2023

Add custom casting feature.

image

Based on Laravel Custom Cast
https://laravel.com/docs/10.x/eloquent-mutators#custom-casts

@edipoReboucas edipoReboucas force-pushed the feat/add-custom-cast branch 9 times, most recently from 2f0612e to 8544f54 Compare October 20, 2023 20:10
@edipoReboucas edipoReboucas changed the base branch from feat/add-datetime-casts to feat/add-enum-casts October 20, 2023 20:10
@edipoReboucas edipoReboucas force-pushed the feat/add-custom-cast branch 3 times, most recently from 78521f0 to d333ab9 Compare October 20, 2023 20:38
@edipoReboucas edipoReboucas force-pushed the feat/add-enum-casts branch 3 times, most recently from d127e87 to f9e2729 Compare October 20, 2023 21:01
@edipoReboucas edipoReboucas reopened this Oct 20, 2023
@edipoReboucas edipoReboucas force-pushed the feat/add-custom-cast branch 4 times, most recently from 2169ed4 to 0eb2128 Compare October 20, 2023 21:37
@edipoReboucas edipoReboucas marked this pull request as draft October 20, 2023 21:40
@edipoReboucas edipoReboucas marked this pull request as ready for review October 20, 2023 21:40
Comment on lines 32 to 36
self::$cache[$castIdentifier] = match (true) {
self::DATE_TIME === $castName => new DateTimeCast(),
self::IMMUTABLE_DATE_TIME === $castName => new ImmutableDateTimeCast(),
is_subclass_of($castName, BackedEnum::class) => new BackedEnumCast($castName),
is_subclass_of($castName, CastInterface::class) => new $castName(...$castOptions),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parece que isso pode crescer e ficar confuso.
Será que vale a pena transformar num método?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feito.

@@ -94,6 +97,7 @@ protected function init()
$this->container = new IlluminateContainer();
$this->cacheComponent = new CacheComponent();
$this->container->instance(CacheComponentInterface::class, $this->cacheComponent);
$this->container->instance(CastResolverInterface::class, new CastResolverCache(new CastResolverStandalone()));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Pacote do Laravel, acredito que sera preciso adicionar um entrada no MongolidServiceProvider.

@edipoReboucas edipoReboucas force-pushed the feat/add-enum-casts branch 2 times, most recently from ffdddb1 to 880c716 Compare October 30, 2023 02:12
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.

8 participants