Closed ivptr closed 3 years ago
That makes sense as PHP won't cast the Configuration object to an array, as it is a collection which in turn is an ArrayObject, but that does not mean it is an array.
Configuration can be cast to an array though which is the original approach that I removed. I don't know why this error hasn't triggered for me but this definitely needs fixing regardless. Either it should be cast to an array or the getArrayCopy method should be used.
It'd be interesting to look into the side effects and performance of either option. Maybe it is a better idea to add a getAsArray method to the Configuration system to avoid casting the entire configuration tree on every access.
Overall I am not happy with the way ConnectionDetails::fromArray works (the enforcement of the root connection key seems arbitrary for one) so I'll likely be rewriting that as well.
Yes, it looks somewhat messy.
Why are you considering performance for this particular thing, connecting is done once only when starting the bot?
In this scenario the performance does not matter as it indeed has to be done just once while starting. However throughout the bot the configuration can be read and I'd like to have a uniform way of turning the tree into an array.
In hindsight, once fromArray has been rewritten though just passing the connection
key of the tree should be enough to turn it into an array, as it is provided as an array in the configuration file. So I'm not sure how much use this would be.
The core issue is the messy method though so I'll fix that.
When trying to run bot getting:
I see the latest commit has changes regarding that function: https://github.com/WildPHP/irc-bot/commit/f5f6dd01787328774bfe7546f62a7cf79dad83e2#diff-09f77239c63a31f8dbdd10fbda706cd8a7063cfa3449e257e2d11854ed59de05