Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Fix autoload to work properly with composer dependencies #401

Merged
merged 2 commits into from
May 16, 2017

Conversation

erayd
Copy link
Contributor

@erayd erayd commented Mar 22, 2017

What

Replace the autoloader in validate-json with the composer one.

Why

Because the current autoloader cannot handle dependencies, which means that validate-json cannot find MabeEnum\Enum.

require_once $fileName;
}
// support running this tool from git checkout
if (is_dir(__DIR__ . '/../vendor')) {
Copy link
Collaborator

@bighappyface bighappyface Mar 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would dirname work better here to help avoid the path directory separator headache?

http://php.net/manual/en/function.dirname.php

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify? PATH_SEPARATOR has nothing to do with filesystem paths - it's the ':' character used as a list separator when defining multiple search paths (ie. what you'll find in the $PATH environment variable). Not sure how dirname has anything to do with that...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I edited the comment to refer to directory separator; I didn't realize my phrasing collided with that other constant at the time I wrote it.

Screwing with relative paths in strings to wire things up always seems dirty to me, especially with directory separators differing between platforms.

An example of what I am suggesting:

$ cd /path/to/json-schema/bin
$ php -a
Interactive shell

php > echo __DIR__;
/path/to/json-schema/bin
php > echo dirname(__DIR__);
/path/to/json-schema
php > echo dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor';
/path/to/json-schema/vendor

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me, I'll do that now.

@shmax
Copy link
Collaborator

shmax commented Mar 22, 2017

Wow, nice! LGTM

}
require($composerAutoload);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curiosity, why not just require __DIR__.'/../vendor/autoload.php'; ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that it can be resolved from anywhere in the include path. If you're asking "why use dirname", that's because @bighappyface doesn't like the relative path & hardcoded Unix directory separator.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, it seems a bit odd to me to alter the include_path to access a file you know the absolute path; but well, in a binary it does not matter much

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems odd to me too. The impression I got from reading the original code is that the author anticipated the utility script being split from the rest of the package and installed elsewhere, and the include path business is because of that. I don't know the reasons behind that approach being present in the code, so I kept it when I made the change.

@erayd erayd changed the title Fix autoload to work properly with composer dependencies [BUGFIX] Fix autoload to work properly with composer dependencies Apr 11, 2017
@erayd erayd mentioned this pull request May 15, 2017
@bighappyface bighappyface merged commit 9fe7822 into jsonrainbow:6.0.0-dev May 16, 2017
@erayd erayd mentioned this pull request May 16, 2017
@erayd erayd deleted the fix-bin-autoload branch May 16, 2017 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants