-
Notifications
You must be signed in to change notification settings - Fork 9
Icon objects #34
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
Icon objects #34
Conversation
I like this, it makes sense to separate an icon from a manager. I'm fine with Good call on the Some thoughts about the API, and with #33 in mind. What if instead of <?= $icons->get('anchor')->color('red')->strokeWidth(3)->attribute('data-label', 'anchor')->attributes(['foo' => 'bar']); ?> (Or put the helper functions and the attribute changes before the For completion's sake, I think there should be additional tests for for the API. Testing things like setting individual attributes and also all the nuances of how attributes are treated (for example |
Just to clear things up regarding the Symfony bundle and Drupal module I've mentioned previously. Best practice is to keep them as separate repos from a generic php library. So I think it makes sense to keep this framework agnostic, but still do things in consideration of what framework glue packages would benefit from, provided it doesn't make the quality of this library worse. Regarding whether to add set/get prefixes to functions. Personally I find including them to be valuable. We will likely be very familiar with the API so if we did drop a prefix, we'd know what the function does without having to dig into docs/source code. But I think the average dev would need to dig in a bit more to know what functions do. By adding a get/set prefix, it's pretty obvious what's going on. I've also been thinking about proposing Looking at your extreme example, I think we should have a mechanism for being able to set a bunch of attributes at once that feels like the current Regardless, I think for next steps, I'll work on the API and write some templates and scenarios and see what feels good and what doesn't and once it feels right, I'll assign back for another review! |
I've rethought about adding attribute modification to the render function, but I don't think it helps in this context, and then it basically acts similarly to just calling I've also moved attribute handling into a trait as that makes sense in our case here. @Pixelrobin I'm curious to get your thoughts on the current state. Ignore the failing tests for now, we'll fix them up once we land on an API to try out. I'd like to focus on getting something close, rather than 100%. I'd like to release an alpha version soon and try this out on some real projects and get some feedback as we might not see something until we go to use it. |
Explicit |
Here's an implementation of #19 (also implements #12 and #33). I usually try to keep a lot of changes separate to make review easier, but sometimes it's necessary to make sure it feels cohesive together.
There's a few benefits we get here. First is the API is basically the same as before. You can do the following.
get()
will now return an Icon object though. Which means that you could get the icon anywhere and be able to manipulate it's attributes up until you decide to render it. This would also work great for serialization so you could store the icon in a message queue or something and then deal with it later on and modify the size, color, etc if you need to before you actually use it.So this gives us the simplicity of what existed before, but allows more advanced usages as well.
A couple things you might have questions about:
IconManager
I was also contemplatingIconRegistry
. Let me know if you prefer the latter or something else.Let me know what you think.