/// <summary> /// Adds session variables aliases to global variables. /// </summary> public void RegisterSessionGlobals() { PhpArray globals, session; // do not create session variables table if not exists: if ((session = PhpReference.AsPhpArray(AutoGlobals.Session)) == null) { return; } // creates globals array if it doesn't exists: globals = GlobalVariables; // iterates using unbreakable enumerator: foreach (KeyValuePair <IntStringKey, object> entry in session) { PhpReference php_ref = entry.Value as PhpReference; // converts the session variable to a reference if it is not one ("no duplicate pointers" rule preserved): if (php_ref == null) { session[entry.Key] = php_ref = new PhpReference(entry.Value); } // adds alias to the globals: globals[entry.Key] = php_ref; } }
/// <summary> /// Ends session, i.e. stores content of the $_SESSION array to the <c>HttpContext.Session</c> collection. /// </summary> /// <param name="abandon">Whether to abandon the session without persisting variables.</param> /// <exception cref="SessionException">Session state not available.</exception> public void EndSession(bool abandon) { // checks and changes session state: if (disposed || sessionState != SessionStates.Started) { return; } sessionState = SessionStates.Closing; if (httpContext.Session == null) { throw new SessionException(CoreResources.GetString("session_state_unavailable")); } GlobalConfiguration global = Configuration.Global; PhpArray variables = PhpReference.AsPhpArray(scriptContext.AutoGlobals.Session); if (variables == null) { variables = new PhpArray(); } try { if (!abandon) { scriptContext.Config.Session.Handler.Persist(variables, scriptContext, httpContext); } else { scriptContext.Config.Session.Handler.Abandoning(scriptContext, httpContext); } } finally { if (!abandon) { // if ASP.NET session state is empty then adds a dump item to preserve the session: if (httpContext.Session.Count == 0) { httpContext.Session.Add(AspNetSessionHandler.PhpNetSessionVars, AspNetSessionHandler.DummySessionItem); } } else { // abandons ASP.NET session: httpContext.Session.Abandon(); } sessionState = SessionStates.Closed; } }