Skip to content

Commit

Permalink
[BUGFIX] Fix autoload to work properly with composer dependencies (#401)
Browse files Browse the repository at this point in the history
* Fix autoload to work properly with composer dependencies

* Use dirname()
  • Loading branch information
erayd authored and bighappyface committed May 16, 2017
1 parent 331d41b commit 9fe7822
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions bin/validate-json
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9fe7822

Please sign in to comment.