-
Notifications
You must be signed in to change notification settings - Fork 356
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,32 +6,19 @@ | |
* @author Christian Weiske <[email protected]> | ||
*/ | ||
|
||
/** | ||
* Dead simple autoloader | ||
* | ||
* @param string $className Name of class to load | ||
* | ||
* @return void | ||
*/ | ||
function __autoload($className) | ||
{ | ||
$className = ltrim($className, '\\'); | ||
$fileName = ''; | ||
if ($lastNsPos = strrpos($className, '\\')) { | ||
$namespace = substr($className, 0, $lastNsPos); | ||
$className = substr($className, $lastNsPos + 1); | ||
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; | ||
} | ||
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; | ||
if (stream_resolve_include_path($fileName)) { | ||
require_once $fileName; | ||
} | ||
// support running this tool from git checkout | ||
$projectDirectory = dirname(__DIR__); | ||
if (is_dir($projectDirectory . DIRECTORY_SEPARATOR . 'vendor')) { | ||
set_include_path($projectDirectory . PATH_SEPARATOR . get_include_path()); | ||
} | ||
|
||
// support running this tool from git checkout | ||
if (is_dir(__DIR__ . '/../src/JsonSchema')) { | ||
set_include_path(__DIR__ . '/../src' . PATH_SEPARATOR . get_include_path()); | ||
// autoload composer classes | ||
$composerAutoload = stream_resolve_include_path('vendor/autoload.php'); | ||
if (!$composerAutoload) { | ||
echo("Cannot load json-schema library\n"); | ||
exit(1); | ||
} | ||
require($composerAutoload); | ||
|
||
$arOptions = array(); | ||
$arArgs = array(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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';
?There was a problem hiding this comment.
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.There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.