-
Notifications
You must be signed in to change notification settings - Fork 27
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
base: feat/add-enum-casts
Are you sure you want to change the base?
Conversation
2f0612e
to
8544f54
Compare
78521f0
to
d333ab9
Compare
d127e87
to
f9e2729
Compare
d333ab9
to
f9e2729
Compare
2169ed4
to
0eb2128
Compare
0eb2128
to
fc979da
Compare
f9e2729
to
01b51e8
Compare
99f0dd5
to
235a6e3
Compare
fc979da
to
0fc19aa
Compare
src/Model/Casts/CastResolver.php
Outdated
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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feito.
0fc19aa
to
ff54360
Compare
@@ -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())); |
There was a problem hiding this comment.
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
.
ff54360
to
a96e7fb
Compare
a96e7fb
to
94a9aed
Compare
ffdddb1
to
880c716
Compare
Add custom casting feature.
Based on Laravel Custom Cast
https://laravel.com/docs/10.x/eloquent-mutators#custom-casts