From bc1948ea71ba5ae64edbf82e3618fc1698d48703 Mon Sep 17 00:00:00 2001 From: Erayd Date: Thu, 23 Mar 2017 10:29:22 +1300 Subject: [PATCH 1/2] Fix autoload to work properly with composer dependencies --- bin/validate-json | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/bin/validate-json b/bin/validate-json index 421ebcde..2eb4561f 100755 --- a/bin/validate-json +++ b/bin/validate-json @@ -6,32 +6,18 @@ * @author Christian Weiske */ -/** - * 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 +if (is_dir(__DIR__ . '/../vendor')) { + set_include_path(__DIR__ . '/..' . 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(); From a31cf7b667f00df626062cb28a90a36befb64e1b Mon Sep 17 00:00:00 2001 From: Erayd Date: Thu, 23 Mar 2017 14:15:43 +1300 Subject: [PATCH 2/2] Use dirname() --- bin/validate-json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/validate-json b/bin/validate-json index 2eb4561f..5de011ce 100755 --- a/bin/validate-json +++ b/bin/validate-json @@ -7,8 +7,9 @@ */ // support running this tool from git checkout -if (is_dir(__DIR__ . '/../vendor')) { - set_include_path(__DIR__ . '/..' . PATH_SEPARATOR . get_include_path()); +$projectDirectory = dirname(__DIR__); +if (is_dir($projectDirectory . DIRECTORY_SEPARATOR . 'vendor')) { + set_include_path($projectDirectory . PATH_SEPARATOR . get_include_path()); } // autoload composer classes