Browse Source

[php] changed `--php-prefix`, `--php-front` and `--php-lib` to `-D` flags

Alexander Kuzmenko 8 years ago
parent
commit
67e4c63365
5 changed files with 18 additions and 30 deletions
  1. 1 0
      extra/CHANGES.txt
  2. 0 13
      src/compiler/main.ml
  3. 4 8
      src/context/common.ml
  4. 6 2
      src/core/define.ml
  5. 7 7
      src/generators/genphp7.ml

+ 1 - 0
extra/CHANGES.txt

@@ -8,6 +8,7 @@
 
 	all : replaced some occurrences of List with Array
 	all : changed haxe.xml.Fast to an abstract
+	php : changed `--php-prefix`, `--php-front` and `--php-lib` to `-D php-prefix=`, `-D php-front=` and `-D php-lib=` respectively
 
 	Removals:
 

+ 0 - 13
src/compiler/main.ml

@@ -644,19 +644,6 @@ try
 			com.foptimize <- false;
 			Common.define com Define.NoOpt;
 		), ": disable code optimizations");
-		("--php-front",Arg.String (fun f ->
-			if com.php_front <> None then raise (Arg.Bad "Multiple --php-front");
-			com.php_front <- Some f;
-		),"<filename> : select the name for the php front file");
-		("--php-lib",Arg.String (fun f ->
-			if com.php_lib <> None then raise (Arg.Bad "Multiple --php-lib");
-			com.php_lib <- Some f;
-		),"<filename> : select the name for the php lib folder");
-		("--php-prefix", Arg.String (fun f ->
-			if com.php_prefix <> None then raise (Arg.Bad "Multiple --php-prefix");
-			com.php_prefix <- Some f;
-			Common.define com Define.PhpPrefix;
-		),"<name> : prefix all classes with given name");
 		("--remap", Arg.String (fun s ->
 			let pack, target = (try ExtString.String.split s ":" with _ -> raise (Arg.Bad "Invalid remap format, expected source:target")) in
 			com.package_rules <- PMap.add pack (Remap target) com.package_rules;

+ 4 - 8
src/context/common.ml

@@ -288,9 +288,6 @@ type context = {
 	mutable resources : (string,string) Hashtbl.t;
 	mutable neko_libs : string list;
 	mutable include_files : (string * string) list;
-	mutable php_front : string option;
-	mutable php_lib : string option;
-	mutable php_prefix : string option;
 	mutable swf_libs : (string * (unit -> Swf.swf) * (unit -> ((string list * string),As3hl.hl_class) Hashtbl.t)) list;
 	mutable java_libs : (string * bool * (unit -> unit) * (unit -> (path list)) * (path -> ((JData.jclass * string * string) option))) list; (* (path,std,close,all_files,lookup) *)
 	mutable net_libs : (string * bool * (unit -> path list) * (path -> IlData.ilclass option)) list; (* (path,std,all_files,lookup) *)
@@ -442,8 +439,10 @@ let raw_defined com v =
 let defined_value com v =
 	Define.defined_value com.defines v
 
-let defined_value_safe com v =
-	Define.defined_value_safe com.defines v
+let defined_value_safe ?default com v =
+	match default with
+		| Some s -> Define.defined_value_safe ~default:s com.defines v
+		| None -> Define.defined_value_safe com.defines v
 
 let define com v =
 	Define.define com.defines v
@@ -631,8 +630,6 @@ let create version s_version args =
 		main = None;
 		flash_version = 10.;
 		resources = Hashtbl.create 0;
-		php_front = None;
-		php_lib = None;
 		swf_libs = [];
 		java_libs = [];
 		net_libs = [];
@@ -641,7 +638,6 @@ let create version s_version args =
 		c_args = [];
 		neko_libs = [];
 		include_files = [];
-		php_prefix = None;
 		js_gen = None;
 		load_extern_type = [];
 		defines = {

+ 6 - 2
src/core/define.ml

@@ -82,6 +82,8 @@ type strict_defined =
 	| Objc
 	| OldConstructorInline
 	| OldErrorFormat
+	| PhpLib
+	| PhpFront
 	| PhpPrefix
 	| RealPosition
 	| ReplaceFiles
@@ -192,6 +194,8 @@ let infos = function
 	| OldConstructorInline -> "old-constructor-inline",("Use old constructor inlining logic (from haxe 3.4.2) instead of the reworked version.",[])
 	| OldErrorFormat -> "old-error-format",("Use Haxe 3.x zero-based column error messages instead of new one-based format.",[])
 	| PhpPrefix -> "php_prefix",("Root namespace for generated php classes. E.g. if compiled with`--php-prefix some.sub`, then all classes will be generated in `\\some\\sub` namespace.",[Platform Php])
+	| PhpLib -> "php_lib",("Select the name for the php lib folder.",[Platform Php])
+	| PhpFront -> "php_front",("Select the name for the php front file (by default: `index.php`).", [Platform Php])
 	| RealPosition -> "real_position",("Disables Haxe source mapping when targetting C#, removes position comments in Java and Php output",[Platforms [Cs;Java;Php]])
 	| ReplaceFiles -> "replace_files",("GenCommon internal",[Platforms [Java;Cs]])
 	| Scriptable -> "scriptable",("GenCPP internal",[Platform Cpp])
@@ -248,9 +252,9 @@ let raw_defined_value ctx k =
 let defined_value ctx v =
 	raw_defined_value ctx (fst (infos v))
 
-let defined_value_safe ctx v =
+let defined_value_safe ?default ctx v =
 	try defined_value ctx v
-	with Not_found -> ""
+	with Not_found -> match default with Some s -> s | None -> ""
 
 let raw_define ctx v =
 	let k,v = try ExtString.String.split v "=" with _ -> v,"1" in

+ 7 - 7
src/generators/genphp7.ml

@@ -184,9 +184,9 @@ let get_php_prefix ctx =
 		| Some prefix -> prefix
 		| None ->
 			let lst =
-				match ctx.php_prefix with
-					| None -> []
-					| Some str ->
+				match Common.defined_value_safe ctx Define.PhpPrefix with
+					| "" -> []
+					| str ->
 						if String.length str = 0 then
 							[]
 						else
@@ -3665,10 +3665,11 @@ class generator (ctx:context) =
 			match self#get_entry_point with
 				| None -> ()
 				| Some (uses, entry_point) ->
-					let filename = match ctx.php_front with None -> "index.php" | Some n -> n in
+					let filename = Common.defined_value_safe ~default:"index.php" ctx Define.PhpFront in
 					let channel = open_out (root_dir ^ "/" ^ filename) in
 					output_string channel "<?php\n";
 					output_string channel uses;
+					output_string channel "\n";
 					output_string channel ("set_include_path(__DIR__.'/" ^ (String.concat "/" self#get_lib_path) ^ "');\n");
 					output_string channel "spl_autoload_register(\n";
 					output_string channel "	function($class){\n";
@@ -3696,9 +3697,8 @@ class generator (ctx:context) =
 			Returns path from `index.php` to directory which will contain all generated classes
 		*)
 		method private get_lib_path : string list =
-			match ctx.php_lib with
-				| None -> ["lib"];
-				| Some path -> (Str.split (Str.regexp "/")  path)
+			let path = Common.defined_value_safe ~default:"lib" ctx Define.PhpLib in
+			(Str.split (Str.regexp "/")  path)
 		(**
 			Returns PHP code for entry point
 		*)