Wouldn't be great to encapsulate the attributes manipulation? That could be very useful eg. in the Request class. Regarding casting I thought of something as simple as:
CastableContract
CastableTrait
abstract class Model implements ArrayAccess, Arrayable, Castable, Jsonable, JsonSerializable, QueueableEntity, UrlRoutable
{
use CastableTrait;
…
}
class Request extends SymfonyRequest implements Arrayable, ArrayAccess, Castable
{
use CastableTrait, Macroable;
…
}
Wouldn't be great to encapsulate the attributes manipulation? That could be very useful eg. in the Request class. Regarding casting I thought of something as simple as:
In combination with custom casting discussed in https://github.com/laravel/framework/pull/16305 and https://github.com/laravel/framework/pull/13706 it could be a very powerfull and yet a clean solution. Another approach could be a
Processor
/Transformer
implementation (this is just a basic idea inspired by the need to encapsulate request data processing):an object/array could be also easily processed with a processor composite:
or maybe better interally by
all()
,input()
,except()
etc.?