From 6ea79db21e715026416245ba3687efb57bdf39f1 Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Fri, 1 May 2009 18:19:07 +0200 Subject: [PATCH] * made the usingPackage function to behave in the case of the same package added multiple times * added an automatic exception folder adding to the include path if exists --- _res/_libs/functions.inc.php | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/_res/_libs/functions.inc.php b/_res/_libs/functions.inc.php index 9cea9b7..d3d0090 100644 --- a/_res/_libs/functions.inc.php +++ b/_res/_libs/functions.inc.php @@ -19,6 +19,23 @@ function exceptions_error_handler ($severity, $message, $filename, $lineno) { throw new ErrorException ($message, 0, $severity, $filename, $lineno); } } + +function d () { + $aRgs = func_get_args(); + $iExit = 1; + + if (php_sapi_name() != 'cli') { + // not running in console + echo '
';
+		$iExit = 0;
+	}
+	foreach ($aRgs as $object) {
+		var_dump($object);
+	}
+
+	die ($iExit);
+}
+
 /**
  * @see usingPackage
  * @param string $sPackageName
@@ -39,14 +56,23 @@ function usingPackage ($packageName) {
 	$pkgPath	= LIB_PATH . DIRECTORY_SEPARATOR . $pkgLower;
 
 	$path 		= get_include_path();
-	if (is_dir($pkgPath) && !strpos ($pkgPath, $path)) {
-		set_include_path(
-			$pkgPath . PATH_SEPARATOR .
-			$path
-		);
+	if (is_dir($pkgPath)) {
+		if (strpos ($path, $pkgPath) === false) {
+			// adding exceptions dir to include path if it exists
+			if (is_dir ($pkgPath. DIRECTORY_SEPARATOR . 'exceptions')) {
+				// adding the exceptions if they exist
+				$pkgPath .= PATH_SEPARATOR . $pkgPath . DIRECTORY_SEPARATOR . 'exceptions';
+			}
+			set_include_path(
+				$path . PATH_SEPARATOR .
+				$pkgPath
+			);
+		} else {
+			echo $pkgPath . "\n";
+		}
 		return true;
 	} else {
-		import ('coreexceptions');
+		usingPackage ('coreexceptions');
 		throw new tsExceptionPackageImport ("bad package " . $packageName);
 	}
 }
@@ -60,13 +86,9 @@ function usingClass ($className) {
 
 
 	$fileIncluded = @include ($classNameLow . '.class.php');
-//	var_dump( $classNameLow . '.class.php');
-//	var_dump( $fileIncluded);
 	if ( !$fileIncluded ) {
-//		var_dump($classNameLow . DIRECTORY_SEPARATOR . $classNameLow . '.class.php');
 		$fileIncluded = @include ($classNameLow . DIRECTORY_SEPARATOR . $classNameLow . '.class.php');
 	}
-//	var_dump($fileIncluded);
 	return $fileIncluded;
 }
 
@@ -135,6 +157,7 @@ if (!function_exists('usingClass')) {
 		}
 	}
 }
+
 /**
  * Dumb function for email validation
  *
-- 
2.11.4.GIT