theseer / Autoload

A lightweight php namespace aware autoload generator and phar archive builder
Other
388 stars 47 forks source link

default basedir #57

Closed remicollet closed 9 years ago

remicollet commented 9 years ago

About defaut basedir. Would it make sense to use directory of output file (if given), so the generated file will be usable) ?

It is quite common to run

 $ phpab  --output  top/foo/autoload.php --basedir  top/foo   top

Because sometime library have file in "top" Without --basedir, default value is "top" which make the generated autoload.php unusable.

Ex : https://github.com/sebastianbergmann/version

Restoring a PSR-0 tree, this will be installed as

/usr/share/php/SebastianBergmann/Version.php
/usr/share/php/SebastianBergmann/Version/autoload.php

Obviously we cannot save the autoloader in top directory (which contains various libraries)

remicollet commented 9 years ago

This is a bug tracker for discussion (I can take care of implementation).

theseer commented 9 years ago

That indeed could work and I do like the idea.

I'm currently trying to decide whether this would be a BC break for anyone as the current default behavior is to consider the first directory to process as base directory (unless explicitly overwritten).

For the majority of my use cases, there shouldn't be any difference as I store the autoload.php file within the src directory. I don't really care too much about PSR-0 or PSR-4 and PSR compliance as the generated map works independently of any file system layout. But I do see the point of using the location of the autoload file as reference.

Obviously every user who had --basedir in place won't see any difference. So the only question is what would (or could?) break when one did not specify basedir?

theseer commented 9 years ago

I guess the current default behavior only works if you place the generated file into the very same directory you are processing. Every other usecase needs tweaking of the basedir setting.

So using the directory of the file as basedir shouldn't do any harm as it would only render the basedir specification superfluous for those cases.

Looking forward to a PR for this :)

theseer commented 9 years ago

Thanks for the effort and the fixes. I'll prepare a new release later today.

remicollet commented 9 years ago

Thanks for merging :)