base58php icon indicating copy to clipboard operation
base58php copied to clipboard

Helper class for static call of encode/decode methods

Open barbushin opened this issue 8 years ago • 4 comments

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.

barbushin avatar Dec 09 '15 03:12 barbushin

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

stephen-hill avatar Dec 09 '15 13:12 stephen-hill

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 :)

barbushin avatar Dec 09 '15 13:12 barbushin

I've created a pull request #15 which addresses the above. Please feel free to let me know what you think.

stephen-hill avatar Dec 13 '15 21:12 stephen-hill

I think it is amazing! thanks a lot for your work!

fabOnReact avatar Aug 20 '20 19:08 fabOnReact