ede-php-autoload icon indicating copy to clipboard operation
ede-php-autoload copied to clipboard

PSR0 support

Open xendk opened this issue 7 years ago • 2 comments

Carrying over from #27 where I wrote:

I tried implementing the other completion, and it was going rather well, until I discovered that the PSR0 loader doesn't quite live up to the spec: http://www.php-fig.org/psr/psr-0/

It's only in class names that the underscores can be used as separator, so the original test that checks if Psr0Ns_T to Psr0Ns_TheClass is wrong. I then carried that misunderstanding on in the subdir handling.

Trying to fix that up gave me all kind of troubles, so before carrying on, I'd like to ask how important underscore completion is? Or could we get away with just always completing with backslashes? I mean, following the specs, Psr0Ns\TheS should offer both Psr0Ns\TheSubdir_ and Psr0Ns\TheSubdir\ as possible completions, and that's, IMHO, just ugly. And if you're using PSR4, backslashes should work just fine.

And @stevenremot wrote:

Ah, that's true. We can open another issue on that, but I think the impact is pretty limited because:

PSR-0 is deprecated Most of the time, you use either namespaces or big class names, so there is not that much risk of mixing stuffs. At least that's my experience

Well, that's where I don't quite follow. I remember the big class names of yore and figured PSR0 tries to retain some compatibility with that, but according to the spec they still need to be prefixed by the vendor namespace.

So the file Dir/Sub_Dir/Class.php can be used as Vendor\Dir\Sub_Dir\Class or Vendor\Dir_Sub_Dir_Class or Vendor\Dir_Sub_Dir\Class or Vendor\Dir\Sub_Dir_Class, but not Vendor\Dir\Sub\Dir\Class or Vendor_Dir_Sub_Dir_Class.

Are you seeing different rules in the wild?

Whatever the case, it needs to match up with the classname actually used in the PHP file, but we can't read that.

In order to live up to the spec, as I see it, completion should simply offer subdirs as both SubDir\ and Subdir_, in order for PSR0 completion being able to provide whatever the user wants to use, and drop any other attempts at guessing. Though it will properly increase the number of completion steps (pressing tab, whatever) for the user, as each directory will basically appear twice. And leave it up to the developer to choose the one used in the PHP file.

Agree?

xendk avatar Apr 16 '17 22:04 xendk