AlekseyKorzun / reCaptcha-PHP-5

Proper PHP 5 client for reCaptcha client
http://www.google.com/recaptcha/intro/index.html
Other
40 stars 26 forks source link

PSR-0 compatibility #4

Open flack opened 11 years ago

flack commented 11 years ago

Right now, this package uses Captcha as its only namespace, which is a bit unfortunate, since it is a very generic namespace which increases the risk of collisions when used e.g. in an environment where multiple captcha implementations are integrated.

It would be better if the namespace would be something like AlekseyKorzun\ReCaptcha, i.e. have a vendor namespace as defined in PSR-0 (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md). If there is a vendor namespace, then the package namespace itself becomes less important, except of course when you decide to implement another captcha mechanism :-)

I know this is a bit inconvenient to implement, since it will break backwards compatibility, but maybe you could do it for a new (major) release.

AlekseyKorzun commented 11 years ago

That makes sense, but since this package has so many installs on Packagist which does not support renaming of projects without removing them first I'm hesitant to do so.

I might look into this more when I get a chance, maybe that's no longer the case.

flack commented 11 years ago

AFAIK packagist still sucks in this regard. They don't allow you to remove packages either if they have more than 50 installs, so this wouldn't work anyways.

But my request is not such much about the name in composer.json, but rather the namespace used in the PHP classes themselves. Right now, you instantiate the widget like this:

$captcha = new Captcha\Captcha();

My proposal would be to use something like this instead:

$captcha = new AlekseyKorzun\ReCaptcha\Captcha();

The packagist setup doesn't have to change for this (but you might need to update the autoloader configuration in composer.json)

AlekseyKorzun commented 11 years ago

Why not just AlekseyKorzun\ReCaptcha ? Any opinion on that?

flack commented 11 years ago

AlekseyKorzun\ReCaptcha works fine for me. I was suggesting the form with two namespaces because it is psr-0 compliant (they want everything in the format VendorName\PackageName\[optional other namespaces]\ClassName). psr-0 is not a real standard, so it's not terribly important to follow it, I just saw in your composer.json that you're using the psr-0 autoloader, but as long as it can find the classes, all is well

AlekseyKorzun commented 11 years ago

Gotcha, that makes sense I did not look at the document they drafted in a while now.

I might do this this weekend, still need to figure out what kind of impact this will do to users not using composer/packagist/etc.

AlekseyKorzun commented 8 years ago

@flack I think this is resolved. Just came across this... lol