base58php
base58php copied to clipboard
Helper class for static call of encode/decode methods
Hi,
This is kind of problem that to call encode/decode methods we need to initiate StephenHill\Base58
instance. There are not so many things to configure, and I guess that 99% users of this library will not override encoding service provider. And passing instance of base58 to DI container also does not look very reasonable.
It will be great to have some kind of StephenHill\StaticBase58
class that provides static encode/decode methods.
Anyway, @stephen-hill, thank you so much for base58php! It's implemented really great.
Hi @barbushin
Thanks for your suggestion. This would be very easy to implement. I have created new branch which I will work on over the weekend.
As well as having a properly named class, I was thinking of putting a class in the root namespace. So that you could call Base58::encode()
or \Base58::encode()
without having a use statement. I know this is bad practice, but it's highly unlikely that someone else or PHP will have a root Base58 class. What are your thoughts?
Otherwise we could encourage people to:
use StephenHill\StaticBase58 as Base58;
Base58::encode();
Cheers Stephen
As well as having a properly named class, I was thinking of putting a class in the root namespace. So that you could call Base58::encode() or \Base58::encode() without having a use statement. I know this is bad practice, but it's highly unlikely that someone else or PHP will have a root Base58 class. What are your thoughts?
I think this is very good idea!
BTW, you can take a look at my solution that I implemented there https://github.com/barbushin/php-console/blob/master/src/PhpConsole/Helper.php So there is also global PC
class that is initialized only when PhpConsole\Heler
is autoloaded, I mean PhpConsole\Helper::register()
.
I think it's universal solution that prevents classes names conflicts. But, in the same moment, I think there is 0% chance that somebody already use Base58
class name, so maybe you can just create global class without any helpers with register method :)
I've created a pull request #15 which addresses the above. Please feel free to let me know what you think.
I think it is amazing! thanks a lot for your work!