2
0
Эх сурвалжийг харах

[php7] implemented php.Lib.loadLib()

Alexander Kuzmenko 8 жил өмнө
parent
commit
59e297dbe6

+ 10 - 0
std/php7/Const.hx

@@ -299,4 +299,14 @@ extern class Const {
 	static var SQLITE3_OPEN_READONLY : Int;
 	static var SQLITE3_OPEN_READWRITE : Int;
 	static var SQLITE3_OPEN_CREATE : Int;
+	/**
+		@see http://php.net/manual/en/function.glob.php
+	**/
+	static var GLOB_MARK : Int;
+	static var GLOB_NOSORT : Int;
+	static var GLOB_NOCHECK : Int;
+	static var GLOB_NOESCAPE : Int;
+	static var GLOB_BRACE : Int;
+	static var GLOB_ONLYDIR : Int;
+	static var GLOB_ERR : Int;
 }

+ 5 - 0
std/php7/Global.hx

@@ -712,6 +712,11 @@ extern class Global {
 	**/
 	static function dirname( path:String, levels:Int = 1 ) : String;
 
+	/**
+		@see http://php.net/manual/en/function.glob.php
+	**/
+	static function glob( pattern:String, flags:Int = 0 ) : NativeArray;
+
 	/**
 		@see http://php.net/manual/en/function.opendir.php
 	**/

+ 12 - 1
std/php7/Lib.hx

@@ -24,6 +24,8 @@ package php;
 import haxe.ds.StringMap;
 import php.Global;
 import php.Throwable;
+import php.Syntax;
+import php.Const;
 
 /**
 	Platform-specific PHP Library. Provides some platform-specific functions
@@ -143,6 +145,15 @@ class Lib {
 		Loads types defined in the specified directory.
 	**/
 	public static function loadLib(pathToLib : String) : Void {
-		throw "Not implemented";
+		var absolutePath = Global.realpath(pathToLib);
+		if(absolutePath == false) throw 'Failed to read path: $pathToLib';
+		Syntax.foreach(Global.glob('$absolutePath/*.php'), function(_, fileName) {
+			if(!Global.is_dir(fileName)) {
+				Global.require_once(fileName);
+			}
+		});
+		Syntax.foreach(Global.glob('$absolutePath/*', Const.GLOB_ONLYDIR), function(_, dirName) {
+			loadLib(dirName);
+		});
 	}
 }