Skip to content

Commit 9fe7822

Browse files
eraydbighappyface
authored andcommitted
[BUGFIX] Fix autoload to work properly with composer dependencies (#401)
* Fix autoload to work properly with composer dependencies * Use dirname()
1 parent 331d41b commit 9fe7822

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

bin/validate-json

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,19 @@
66
* @author Christian Weiske <[email protected]>
77
*/
88

9-
/**
10-
* Dead simple autoloader
11-
*
12-
* @param string $className Name of class to load
13-
*
14-
* @return void
15-
*/
16-
function __autoload($className)
17-
{
18-
$className = ltrim($className, '\\');
19-
$fileName = '';
20-
if ($lastNsPos = strrpos($className, '\\')) {
21-
$namespace = substr($className, 0, $lastNsPos);
22-
$className = substr($className, $lastNsPos + 1);
23-
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
24-
}
25-
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
26-
if (stream_resolve_include_path($fileName)) {
27-
require_once $fileName;
28-
}
9+
// support running this tool from git checkout
10+
$projectDirectory = dirname(__DIR__);
11+
if (is_dir($projectDirectory . DIRECTORY_SEPARATOR . 'vendor')) {
12+
set_include_path($projectDirectory . PATH_SEPARATOR . get_include_path());
2913
}
3014

31-
// support running this tool from git checkout
32-
if (is_dir(__DIR__ . '/../src/JsonSchema')) {
33-
set_include_path(__DIR__ . '/../src' . PATH_SEPARATOR . get_include_path());
15+
// autoload composer classes
16+
$composerAutoload = stream_resolve_include_path('vendor/autoload.php');
17+
if (!$composerAutoload) {
18+
echo("Cannot load json-schema library\n");
19+
exit(1);
3420
}
21+
require($composerAutoload);
3522

3623
$arOptions = array();
3724
$arArgs = array();

0 commit comments

Comments
 (0)