From ed9b20c3d9248d66fed304ec2c0344670864054c Mon Sep 17 00:00:00 2001 From: Phy Date: Sun, 19 Jan 2020 22:08:44 -0500 Subject: [PATCH 1/2] Add test script to composer.json Run test by using `composer test` directly. > Note: Before executing scripts, Composer's bin-dir is temporarily pushed on top of the PATH environment variable so that binaries of dependencies are easily accessible. In this example no matter if the phpunit binary is actually in vendor/bin/phpunit or bin/phpunit it will be found and executed. > > https://getcomposer.org/doc/articles/scripts.md --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index b30def55..23676c4d 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,9 @@ "PhpCas\\": "test/CAS/" } }, + "scripts": { + "test": "phpunit" + }, "extra": { "branch-alias": { "dev-master": "1.3.x-dev" From f9e6947642253d25012eec181a5a0f48ad65f5d9 Mon Sep 17 00:00:00 2001 From: Phy Date: Sun, 19 Jan 2020 22:19:07 -0500 Subject: [PATCH 2/2] Prepare for PhpCas namespace parsing of legacy autoload code - Remove closing PHP tag - Map PhpCas namespace to CAS folder - Use DIRECTORY_SEPARATOR if possible --- source/CAS/Autoload.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/source/CAS/Autoload.php b/source/CAS/Autoload.php index 436f9de4..ee803cbf 100644 --- a/source/CAS/Autoload.php +++ b/source/CAS/Autoload.php @@ -26,18 +26,24 @@ function CAS_autoload($class) // Static to hold the Include Path to CAS static $include_path; // Check only for CAS classes - if (substr($class, 0, 4) !== 'CAS_') { + if (substr($class, 0, 4) !== 'CAS_' && substr($class, 0, 7) !== 'PhpCas\\') { return false; } + // Setup the include path if it's not already set from a previous call if (empty($include_path)) { $include_path = array(dirname(__DIR__)); } // Declare local variable to store the expected full path to the file - foreach ($include_path as $path) { - $file_path = $path . '/' . str_replace('_', '/', $class) . '.php'; + $class_path = str_replace('_', DIRECTORY_SEPARATOR, $class); + // PhpCas namespace mapping + if (substr($class_path, 0, 7) === 'PhpCas\\') { + $class_path = 'CAS' . DIRECTORY_SEPARATOR . substr($class_path, 7); + } + + $file_path = $path . DIRECTORY_SEPARATOR . $class_path . '.php'; $fp = @fopen($file_path, 'r', true); if ($fp) { fclose($fp); @@ -54,6 +60,7 @@ function CAS_autoload($class) return true; } } + $e = new Exception( 'Class ' . $class . ' could not be loaded from ' . $file_path . ', file does not exist (Path="' @@ -85,6 +92,4 @@ function CAS_autoload($class) // it to the autoload stack spl_autoload_register('__autoload'); } -} - -?> +} \ No newline at end of file