/Source.DLR/Core/GlobalVariables.CLR.cs
C# | 784 lines | 462 code | 117 blank | 205 comment | 99 complexity | 83d56c919bd87e9c35f039478a85da64 MD5 | raw file
Possible License(s): CPL-1.0, GPL-2.0, CC-BY-SA-3.0, MPL-2.0-no-copyleft-exception, Apache-2.0
- /*
-
- Copyright (c) 2004-2006 Tomas Matousek.
-
- The use and distribution terms for this software are contained in the file named License.txt,
- which can be found in the root of the Phalanger distribution. By using this software
- in any fashion, you are agreeing to be bound by the terms of this license.
-
- You must not remove this notice from this software.
-
- */
-
- using System;
- using System.IO;
- using System.Diagnostics;
- using System.Collections;
- using System.Collections.Generic;
- using System.Web;
- using System.Web.SessionState;
- using System.Collections.Specialized;
- using System.Reflection;
- using PHP.Core.Emit;
-
- namespace PHP.Core
- {
- /// <summary>
- /// Declares auto-global variables stored in the script context.
- /// </summary>
- public sealed class AutoGlobals
- {
- internal const int EgpcsCount = 5;
- internal const int MaxCount = 9;
- internal const int EstimatedUserGlobalVariableCount = 15;
-
- #region Enumeration
-
- /// <summary>
- /// File upload errors.
- /// </summary>
- public enum PostedFileError
- {
- /// <summary>
- /// No error.
- /// </summary>
- None,
-
- /// <summary>
- /// The uploaded file exceeds the "upload_max_filesize" configuration option. Not supported.
- /// Request is not processed when exceeding maximal size of posted file set in ASP.NET config.
- /// </summary>
- SizeExceededOnServer,
-
- /// <summary>
- /// The uploaded file exceeds the "MAX_FILE_SIZE" value specified in the form. Not supported.
- /// </summary>
- SizeExceededOnClient,
-
- /// <summary>
- /// The uploaded file was only partially uploaded. Not supported.
- /// </summary>
- Partial,
-
- /// <summary>
- /// No file was uploaded.
- /// </summary>
- NoFile
- }
-
- #endregion
-
- #region Fields
-
- /// <summary>
- /// <para>
- /// If server context is available contains server variables ($_SERVER).
- /// Moreover, it contains <c>PHP_SELF</c> - a virtual path to the executing script and
- /// if <see cref="GlobalConfiguration.GlobalVariablesSection.RegisterArgcArgv"/> is set it contains also
- /// <c>argv</c> (an array containing a query string as its one and only element) and
- /// <c>argc</c> which is set to zero.
- /// </para>
- /// <para>
- /// If server context is not available contains empty array (unlike PHP which does fill it with <see cref="Env"/>
- /// and then adds some empty items).
- /// </para>
- /// </summary>
- public PhpReference/*!*/ Server = new PhpReference();
- public const string ServerName = "_SERVER";
-
- /// <summary>
- /// Environment variables ($_ENV).
- /// </summary>
- public PhpReference/*!*/ Env = new PhpReference();
- public const string EnvName = "_ENV";
-
- /// <summary>
- /// Global variables ($GLOBALS).
- /// </summary>
- public PhpReference/*!*/ Globals = new PhpReference();
- public const string GlobalsName = "GLOBALS";
-
- /// <summary>
- /// Request variables ($_REQUEST) copied from $_GET, $_POST and $_COOKIE arrays.
- /// </summary>
- public PhpReference/*!*/ Request = new PhpReference();
- public const string RequestName = "_REQUEST";
-
- /// <summary>
- /// Variables passed by HTTP GET method ($_GET).
- /// </summary>
- public PhpReference/*!*/ Get = new PhpReference();
- public const string GetName = "_GET";
-
- /// <summary>
- /// Variables passed by HTTP POST method ($_POST).
- /// </summary>
- public PhpReference/*!*/ Post = new PhpReference();
- public const string PostName = "_POST";
-
- /// <summary>
- /// Cookies ($_COOKIE).
- /// </summary>
- public PhpReference/*!*/ Cookie = new PhpReference();
- public const string CookieName = "_COOKIE";
-
- /// <summary>
- /// Uploaded files information ($_FILES).
- /// </summary>
- public PhpReference/*!*/ Files = new PhpReference();
- public const string FilesName = "_FILES";
-
- /// <summary>
- /// Session variables ($_SESSION). Initialized on session start.
- /// </summary>
- public PhpReference/*!*/ Session = new PhpReference();
- public const string SessionName = "_SESSION";
-
- #endregion
-
- #region IsAutoGlobal
-
- /// <summary>
- /// Checks whether a specified name is the name of an auto-global variable.
- /// </summary>
- /// <param name="name">The name.</param>
- /// <returns>Whether <paramref name="name"/> is auto-global.</returns>
- public static bool IsAutoGlobal(string name)
- {
- switch (name)
- {
- case "GLOBALS":
- case "_SERVER":
- case "_ENV":
- case "_COOKIE":
- case "_FILES":
- case "_REQUEST":
- case "_GET":
- case "_POST":
- case "_SESSION":
- return true;
- }
- return false;
- }
-
- #endregion
-
- #region Variable Addition
-
- /// <summary>
- /// Adds a variable to auto-global array.
- /// </summary>
- /// <param name="array">The array.</param>
- /// <param name="name">A unparsed name of variable.</param>
- /// <param name="value">A value to be added.</param>
- /// <param name="isGpc">Whether the array is GET, POST or COOKIE (value will be slashed then).</param>
- /// <param name="config">A configuration record.</param>
- /// <param name="subname">A name of intermediate array inserted before the value.</param>
- private static void AddVariable(
- PhpArray/*!*/ array,
- string name,
- object value,
- string subname,
- bool isGpc,
- LocalConfiguration/*!*/ config)
- {
- if (config == null)
- throw new ArgumentNullException("config");
- if (array == null)
- throw new ArgumentNullException("array");
- if (name == null)
- name = String.Empty;
-
- value = GpcEncodeValue(value, isGpc, config);
-
- string key;
-
- // current left and right square brace positions:
- int left, right;
-
- // checks pattern {var_name}[{key1}][{key2}]...[{keyn}] where var_name is [^[]* and keys are [^]]*:
- left = name.IndexOf('[');
- if (left > 0 && left < name.Length - 1 && (right = name.IndexOf(']', left + 1)) >= 0)
- {
- // the variable name is a key to the "array", dots are replaced by underscores in top-level name:
- key = name.Substring(0, left).Replace('.', '_');
-
- // ensures that all [] operators in the chain except for the last one are applied on an array:
- for (;;)
- {
- // adds a level keyed by "key":
- array = Operators.EnsureItemIsArraySimple(array, key);
-
- // adds a level keyed by "subname" (once only):
- if (subname != null)
- {
- array = Operators.EnsureItemIsArraySimple(array, subname);
- subname = null;
- }
-
- // next key:
- key = name.Substring(left + 1, right - left - 1);
-
- // breaks if ']' is not followed by '[':
- left = right + 1;
- if (left == name.Length || name[left] != '[') break;
-
- // the next right brace:
- right = name.IndexOf(']', left + 1);
- }
-
- if (key.Length > 0)
- array.SetArrayItem(key, value);
- else
- array.Add(value);
- }
- else
- {
- // no array pattern in variable name, "name" is a top-level key:
- name = name.Replace('.', '_');
-
- // inserts a subname on the next level:
- if (subname != null)
- Operators.EnsureItemIsArraySimple(array, name)[subname] = value;
- else
- array[name] = value;
- }
- }
-
- private static object GpcEncodeValue(object value, bool isGpc, LocalConfiguration config)
- {
- string svalue = value as string;
- if (svalue != null && isGpc)
- {
- // url-decodes the values:
- svalue = HttpUtility.UrlDecode(svalue, Configuration.Application.Globalization.PageEncoding);
-
- // quotes the values:
- if (Configuration.Global.GlobalVariables.QuoteGpcVariables)
- {
- if (config.Variables.QuoteInDbManner)
- svalue = StringUtils.AddDbSlashes(svalue);
- svalue = StringUtils.AddCSlashes(svalue, true, true);
- }
-
- value = svalue;
- }
-
- return value;
- }
-
- /// <summary>
- /// Adds variables from one auto-global array to another.
- /// </summary>
- /// <param name="dst">The target array.</param>
- /// <param name="src">The source array.</param>
- /// <remarks>Variable values are deeply copied.</remarks>
- /// <exception cref="ArgumentNullException"><paramref name="dst"/> is a <B>null</B> reference.</exception>
- /// <exception cref="ArgumentNullException"><paramref name="src"/> is a <B>null</B> reference.</exception>
- private static void AddVariables(PhpArray/*!*/ dst, PhpArray/*!*/ src)
- {
- Debug.Assert(dst != null && src != null);
-
- foreach (KeyValuePair<IntStringKey, object> entry in src)
- dst[entry.Key] = PhpVariable.DeepCopy(entry.Value);
- }
-
- /// <summary>
- /// Adds variables from one auto-global array to another.
- /// </summary>
- /// <param name="dst">A PHP reference to the target array.</param>
- /// <param name="src">A PHP reference to the source array.</param>
- /// <remarks>
- /// Variable values are deeply copied.
- /// If either reference is a <B>null</B> reference or doesn't contain an array, no copying takes place.
- /// </remarks>
- internal static void AddVariables(PhpReference/*!*/ dst, PhpReference/*!*/ src)
- {
- if (dst != null && src != null)
- {
- PhpArray adst = dst.Value as PhpArray;
- PhpArray asrc = src.Value as PhpArray;
- if (adst != null && asrc != null)
- AddVariables(adst, asrc);
- }
- }
-
- /// <summary>
- /// Loads variables from a collection.
- /// </summary>
- /// <param name="result">An array where to add variables stored in the collection.</param>
- /// <param name="collection">The collection.</param>
- /// <param name="isGpc">Whether the array is GET, POST or COOKIE.</param>
- /// <param name="config">A configuration record.</param>
- private static void LoadFromCollection(PhpArray result, NameValueCollection collection, bool isGpc, LocalConfiguration config)
- {
- foreach (string name in collection)
- {
- // gets all values associated with the name:
- string[] values = collection.GetValues(name);
-
- // adds all items:
- if (name != null)
- {
- for (int i = 0; i < values.Length; i++)
- AddVariable(result, name, values[i] as string, null, false, config);
- }
- else
- {
- // if name is null, only name of the variable is stated:
- // e.g. for GET variables, URL looks like this: ...&test&...
- // we add the name of the variable and an emtpy string to get what PHP gets:
- for (int i = 0; i < values.Length; i++)
- AddVariable(result, values[i], String.Empty, null, false, config);
- }
-
- }
- }
-
- #endregion
-
- #region Initialization
-
- /// <summary>
- /// Initializes all auto-global variables.
- /// </summary>
- internal void Initialize(LocalConfiguration config/*!*/, HttpContext context)
- {
- Debug.Assert(config != null);
- HttpRequest request = (context != null) ? context.Request : null;
-
- // $_ENV:
- InitializeEnvironmentVariables(config);
-
- // $_SERVER:
- InitializeServerVariables(config, context);
-
- // $_GET, $_POST, $_COOKIE, $_REQUEST:
- InitializeGetPostCookieRequestVariables(config, request);
-
- // $_SESSION (initialized by session_start)
-
- // $_FILE:
- InitializeFileVariables(config, request);
-
- // $GLOBALS:
- InitializeGlobals(config, request);
- }
-
- /// <summary>
- /// Loads $_ENV from Environment.GetEnvironmentVariables().
- /// </summary>
- private void InitializeEnvironmentVariables(LocalConfiguration/*!*/ config)
- {
- Debug.Assert(config != null);
-
- IDictionary env_vars = Environment.GetEnvironmentVariables();
- PhpArray array = new PhpArray(0, env_vars.Count);
-
- foreach (DictionaryEntry entry in env_vars)
- AddVariable(array, entry.Key as string, entry.Value as string, null, false, config);
-
- Env.Value = array;
- }
-
- /// <summary>
- /// Loads $_SERVER from HttpRequest.ServerVariables.
- /// </summary>
- private void InitializeServerVariables(LocalConfiguration/*!*/ config, HttpContext context)
- {
- Debug.Assert(config != null);
-
- PhpArray array, argv;
-
- if (context != null)
- {
- array = new PhpArray(0, context.Request.ServerVariables.Count);
-
- // adds variables defined by ASP.NET and IIS:
- LoadFromCollection(array, context.Request.ServerVariables, false, config);
-
- // adds argv, argc variables:
- if (Configuration.Global.GlobalVariables.RegisterArgcArgv)
- {
- array["argv"] = argv = new PhpArray();
- argv.Add(context.Request.ServerVariables["QUERY_STRING"]);
- array["argc"] = 0;
- }
-
- // additional variables defined in PHP manual:
- array["PHP_SELF"] = context.Request.Path;
-
- try
- {
- array["DOCUMENT_ROOT"] = context.Request.MapPath("/"); // throws exception under mod_aspdotnet
- }
- catch (Exception)
- {
- array["DOCUMENT_ROOT"] = null;
- }
-
- array["SERVER_ADDR"] = context.Request.ServerVariables["LOCAL_ADDR"];
- array["REQUEST_URI"] = context.Request.RawUrl;
- array["REQUEST_TIME"] = DateTimeUtils.UtcToUnixTimeStamp(context.Timestamp.ToUniversalTime());
- array["SCRIPT_FILENAME"] = context.Request.PhysicalPath;
- }
- else
- {
- array = new PhpArray(0, 0);
- }
-
- Server.Value = array;
- }
-
-
- /// <summary>
- /// Loads $_GET, $_POST, $_COOKIE, and $_REQUEST arrays.
- /// </summary>
- private void InitializeGetPostCookieRequestVariables(LocalConfiguration/*!*/ config, HttpRequest request)
- {
- Debug.Assert(config != null);
-
- PhpArray get_array, post_array, cookie_array, request_array;
-
- InitializeGetPostVariables(config, request, out get_array, out post_array);
- InitializeCookieVariables(config, request, out cookie_array);
- InitializeRequestVariables(request, config.Variables.RegisteringOrder,
- get_array, post_array, cookie_array, out request_array);
-
- Get.Value = get_array;
- Post.Value = post_array;
- Cookie.Value = cookie_array;
- Request.Value = request_array;
- }
-
- /// <summary>
- /// Loads $_GET, $_POST arrays from HttpRequest.QueryString and HttpRequest.Form.
- /// </summary>
- /// <param name="config">Local configuration.</param>
- /// <param name="request">HTTP request instance or a <B>null</B> reference.</param>
- /// <param name="getArray">Resulting $_GET array.</param>
- /// <param name="postArray">Resulting $_POST array.</param>
- /// <exception cref="ArgumentNullException"><paranref name="config"/> is a <B>null</B> reference.</exception>
- public static void InitializeGetPostVariables(LocalConfiguration/*!*/ config, HttpRequest request,
- out PhpArray getArray, out PhpArray postArray)
- {
- if (config == null)
- throw new ArgumentNullException("config");
-
- if (request != null)
- {
- if (request.RequestType == "GET")
- {
- getArray = new PhpArray(0, request.QueryString.Count + request.Form.Count);
- postArray = new PhpArray(0, 0);
-
- // loads Form variables to GET array:
- LoadFromCollection(getArray, request.Form, true, config);
- }
- else
- {
- getArray = new PhpArray(0, request.QueryString.Count);
- postArray = new PhpArray(0, request.Form.Count);
-
- // loads Form variables to POST array:
- LoadFromCollection(postArray, request.Form, true, config);
- }
-
- // loads Query variables to GET array:
- LoadFromCollection(getArray, request.QueryString, true, config);
- }
- else
- {
- getArray = new PhpArray(0, 0);
- postArray = new PhpArray(0, 0);
- }
- }
-
-
- /// <summary>
- /// Loads $_COOKIE arrays from HttpRequest.Cookies.
- /// </summary>
- /// <param name="config">Local configuration.</param>
- /// <param name="request">HTTP request instance or a <B>null</B> reference.</param>
- /// <param name="cookieArray">Resulting $_COOKIE array.</param>
- /// <exception cref="ArgumentNullException"><paranref name="config"/> is a <B>null</B> reference.</exception>
- public static void InitializeCookieVariables(LocalConfiguration/*!*/ config, HttpRequest request,
- out PhpArray cookieArray)
- {
- if (config == null)
- throw new ArgumentNullException("config");
-
- if (request != null)
- {
- cookieArray = new PhpArray(0, request.Cookies.Count);
-
- foreach (string cookie_name in request.Cookies)
- {
- HttpCookie cookie = request.Cookies[cookie_name];
- AddVariable(cookieArray, cookie.Name, cookie.Value, null, true, config);
-
- // adds a copy of cookie with the same key as the session name;
- // the name gets encoded and so $_COOKIE[session_name()] doesn't work then:
- if (cookie.Name == AspNetSessionHandler.AspNetSessionName)
- cookieArray[AspNetSessionHandler.AspNetSessionName] = GpcEncodeValue(cookie.Value, true, config);
- }
- }
- else
- {
- cookieArray = new PhpArray(0, 0);
- }
- }
-
- /// <summary>
- /// Loads $_REQUEST from $_GET, $_POST and $_COOKIE arrays.
- /// </summary>
- private static void InitializeRequestVariables(HttpRequest request, string/*!*/ gpcOrder,
- PhpArray/*!*/ getArray, PhpArray/*!*/ postArray, PhpArray/*!*/ cookieArray, out PhpArray requestArray)
- {
- Debug.Assert(gpcOrder != null && getArray != null && postArray != null && cookieArray != null);
-
- if (request != null)
- {
- requestArray = new PhpArray(0, getArray.Count + postArray.Count + cookieArray.Count);
-
- // adds items from GET, POST, COOKIE arrays in the order specified by RegisteringOrder config option:
- for (int i = 0; i < gpcOrder.Length; i++)
- {
- switch (Char.ToUpper(gpcOrder[i]))
- {
- case 'G': AddVariables(requestArray, getArray); break;
- case 'P': AddVariables(requestArray, postArray); break;
- case 'C': AddVariables(requestArray, cookieArray); break;
- }
- }
- }
- else
- {
- requestArray = new PhpArray(0, 0);
- }
- }
-
- /// <summary>
- /// Loads $_FILES from HttpRequest.Files.
- /// </summary>
- /// <remarks>
- /// <list type="bullet">
- /// <item>$_FILES[{var_name}]['name'] - The original name of the file on the client machine.</item>
- /// <item>$_FILES[{var_name}]['type'] - The mime type of the file, if the browser provided this information. An example would be "image/gif".</item>
- /// <item>$_FILES[{var_name}]['size'] - The size, in bytes, of the uploaded file.</item>
- /// <item>$_FILES[{var_name}]['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.</item>
- /// <item>$_FILES[{var_name}]['error'] - The error code associated with this file upload.</item>
- /// </list>
- /// </remarks>
- private void InitializeFileVariables(LocalConfiguration/*!*/ config, HttpRequest request)
- {
- Debug.Assert(config != null);
- PhpArray files;
- string path;
- int count;
-
- GlobalConfiguration global_config = Configuration.Global;
-
- if (request != null && global_config.PostedFiles.Accept && (count = request.Files.Count) > 0)
- {
- files = new PhpArray(0, count);
-
- // gets a path where temporary files are stored:
- path = global_config.PostedFiles.GetTempPath(global_config.SafeMode);
-
- for (int i = 0; i < count; i++)
- {
- string name = request.Files.GetKey(i);
- string file_path, type, file_name;
- HttpPostedFile file = request.Files[i];
- PostedFileError error = PostedFileError.None;
-
- if (file.FileName != String.Empty)
- {
- type = file.ContentType;
- file_path = Path.Combine(path, RequestContext.GetTempFileName());
- file_name = Path.GetFileName(file.FileName);
-
- // registers the temporary file for deletion at request end:
- RequestContext.AddTemporaryFile(file_path);
-
- // saves uploaded content to the temporary file:
- file.SaveAs(file_path);
- }
- else
- {
- file_path = type = file_name = String.Empty;
- error = PostedFileError.NoFile;
- }
-
- AddVariable(files, name, file_name, "name", false, config);
- AddVariable(files, name, type, "type", false, config);
- AddVariable(files, name, file_path, "tmp_name", false, config);
- AddVariable(files, name, (int)error, "error", false, config);
- AddVariable(files, name, file.ContentLength, "size", false, config);
- }
- }
- else
- {
- files = new PhpArray(0, 0);
- }
-
- Files.Value = files;
- }
-
- /// <summary>
- /// Adds file variables from $_FILE array to $GLOBALS array.
- /// </summary>
- /// <param name="globals">$GLOBALS array.</param>
- /// <param name="files">$_FILES array.</param>
- private void AddFileVariablesToGlobals(PhpArray/*!*/ globals, PhpArray/*!*/ files)
- {
- foreach (KeyValuePair<IntStringKey, object> entry in files)
- {
- PhpArray file_info = (PhpArray)entry.Value;
-
- globals[entry.Key] = file_info["tmp_name"];
- globals[entry.Key.ToString() + "_name"] = file_info["name"];
- globals[entry.Key.ToString() + "_type"] = file_info["type"];
- globals[entry.Key.ToString() + "_size"] = file_info["size"];
- }
- }
-
- /// <summary>
- /// Loads $GLOBALS from $_ENV, $_REQUEST, $_SERVER and $_FILES.
- /// </summary>
- private void InitializeGlobals(LocalConfiguration/*!*/ config, HttpRequest/*!*/ request)
- {
- Debug.Assert(config != null && Request.Value != null && Env.Value != null && Server.Value != null && Files.Value != null);
-
- PhpArray globals;
- GlobalConfiguration global = Configuration.Global;
-
- // estimates the initial capacity of $GLOBALS array:
- int count = EstimatedUserGlobalVariableCount + AutoGlobals.MaxCount;
- if (global.GlobalVariables.RegisterLongArrays) count += AutoGlobals.MaxCount;
-
- // adds EGPCS variables as globals:
- if (global.GlobalVariables.RegisterGlobals)
- {
- PhpArray env_array = (PhpArray)Env.Value;
- PhpArray get_array = (PhpArray)Get.Value;
- PhpArray post_array = (PhpArray)Post.Value;
- PhpArray files_array = (PhpArray)Files.Value;
- PhpArray cookie_array = (PhpArray)Cookie.Value;
- PhpArray server_array = (PhpArray)Server.Value;
- PhpArray request_array = (PhpArray)Request.Value;
-
- if (request != null)
- {
- globals = new PhpArray(0, count + env_array.Count + request_array.Count + server_array.Count + files_array.Count * 4);
-
- // adds items in the order specified by RegisteringOrder config option (overwrites existing):
- string order = config.Variables.RegisteringOrder;
- for (int i = 0; i < order.Length; i++)
- {
- switch (order[i])
- {
- case 'E': AddVariables(globals, env_array); break;
- case 'G': AddVariables(globals, get_array); break;
-
- case 'P':
- AddVariables(globals, post_array);
- AddFileVariablesToGlobals(globals, files_array);
- break;
-
- case 'C': AddVariables(globals, cookie_array); break;
- case 'S': AddVariables(globals, server_array); break;
- }
- }
- }
- else
- {
- globals = new PhpArray(0, count + env_array.Count);
- AddVariables(globals, env_array);
- }
- }
- else
- {
- globals = new PhpArray(0, count);
- }
-
- // command line argc, argv:
- if (request == null)
- {
- string[] args = Environment.GetCommandLineArgs();
- PhpArray argv = new PhpArray(0, args.Length);
-
- // adds all arguments to the array (the 0-th argument is not '-' as in PHP but the program file):
- for (int i = 0; i < args.Length; i++)
- argv.Add(i, args[i]);
-
- globals["argv"] = argv;
- globals["argc"] = args.Length;
- }
-
- // adds auto-global variables (overwrites potential existing variables in $GLOBALS):
- globals[GlobalsName] = Globals;
- globals[EnvName] = Env;
- globals[GetName] = Get;
- globals[PostName] = Post;
- globals[CookieName] = Cookie;
- globals[RequestName] = Request;
- globals[ServerName] = Server;
- globals[FilesName] = Files;
- globals[SessionName] = Session;
-
- // adds long arrays:
- if (Configuration.Global.GlobalVariables.RegisterLongArrays)
- {
- globals.Add("HTTP_ENV_VARS", new PhpReference(((PhpArray)Env.Value).DeepCopy()));
- globals.Add("HTTP_GET_VARS", new PhpReference(((PhpArray)Get.Value).DeepCopy()));
- globals.Add("HTTP_POST_VARS", new PhpReference(((PhpArray)Post.Value).DeepCopy()));
- globals.Add("HTTP_COOKIE_VARS", new PhpReference(((PhpArray)Cookie.Value).DeepCopy()));
- globals.Add("HTTP_SERVER_VARS", new PhpReference(((PhpArray)Server.Value).DeepCopy()));
- globals.Add("HTTP_POST_FILES", new PhpReference(((PhpArray)Files.Value).DeepCopy()));
-
- // both session array references the same array:
- globals.Add("HTTP_SESSION_VARS", Session);
- }
-
- Globals.Value = globals;
- }
-
- #endregion
-
- #region Emit Support
-
- /// <summary>
- /// Returns 'FieldInfo' representing field in AutoGlobals for given global variable name.
- /// </summary>
- internal static FieldInfo GetFieldForVariable(VariableName name)
- {
- switch (name.ToString())
- {
- case AutoGlobals.CookieName:
- return Fields.AutoGlobals.Cookie;
- case AutoGlobals.EnvName:
- return Fields.AutoGlobals.Env;
- case AutoGlobals.FilesName:
- return Fields.AutoGlobals.Files;
- case AutoGlobals.GetName:
- return Fields.AutoGlobals.Get;
- case AutoGlobals.GlobalsName:
- return Fields.AutoGlobals.Globals;
- case AutoGlobals.PostName:
- return Fields.AutoGlobals.Post;
- case AutoGlobals.RequestName:
- return Fields.AutoGlobals.Request;
- case AutoGlobals.ServerName:
- return Fields.AutoGlobals.Server;
- case AutoGlobals.SessionName:
- return Fields.AutoGlobals.Session;
- default:
- return null;
- }
- }
-
- #endregion
- }
- }