codeigniter4/settings

Type Casting

MGatner opened this issue · 3 comments

Note that boolean true/false will be converted to strings :true and :false when stored in the database, but will be converted back into a boolean when retrieved. Arrays and objects are serialized when saved, and unserialized when retrieved.

One of the most recent additions to Tatter\Settings was type casting - storing the actual setting type in the database so the Library can cast it upon retrieval. I would love to see something like that added here, even if it was "optional" (or auto-detect during set()).

That's a good idea. I like that.

That was quick! Your implementation looks solid, but let me also suggest another route: use Entity to handle the casts since it already has designated cast handlers. There are a few ways to do this but in my library I actually return a Setting Entity itself: https://github.com/tattersoftware/codeigniter4-settings/blob/develop/src/Entities/Setting.php

Of course the classes could just be used to handle conversions internally too.

I saw your solution and it uses CI's tools great :) I wanted to keep this one as light as possible, especially since we're loading up all of the settings and caching in the class. Since PHP had built in tools for it, I thought it made since to use them and keep it slim.