/// <summary> /// Binds parameters after an external function or method invocation. /// </summary> /// <param name="moduleName">Name of the calling module - variables are kept separate for every module</param> /// <param name="args">The parameter array as passed to <see cref="InvokeFunction"/> or <see cref="InvokeMethod"/>.</param> /// <param name="refInfo">The <c>refInfo</c> array as passed to <see cref="InvokeFunction"/> or <see cref="InvokeMethod"/>. /// </param> /// <param name="extMan">The <c>ExtManager</c> through which the function/method was invoked.</param> /// <param name="paramsToBind">Cannot be null. Result of <see cref="PrepareParametersForBinding"/> called prior to the function/method invocation itself.</param> public static void BindParameters(string moduleName, object[] args, int[] refInfo, IExternals extMan, PhpReference[]/*!*/paramsToBind) { Debug.Assert(paramsToBind != null); PhpReference reference; Dictionary<PhpReference, IExternalVariable> moduleVars = null; bool checkUnbind = (boundVariables != null && boundVariables.TryGetValue(moduleName, out moduleVars)); for (int i = 0; i < paramsToBind.Length; ++i) { if ((reference = paramsToBind[i]) != null) { // release the old binding of this variable (if it exists) IExternalVariable ext_var; if (checkUnbind) { Debug.Assert(moduleVars != null); if (moduleVars.TryGetValue(reference, out ext_var)) ext_var.Unbind(); } else { // construct everything as needed if (moduleVars == null) { if (boundVariables == null) boundVariables = new Dictionary<string, Dictionary<PhpReference, IExternalVariable>>(); moduleVars = new Dictionary<PhpReference, IExternalVariable>(); boundVariables.Add(moduleName, moduleVars); } } // bind ext_var = (extMan != null) ? extMan.BindParameter(i) : null; if (ext_var != null) moduleVars[reference] = ext_var; // update the variable if it was passed byref if (refInfo != null) { int index, j = 0; while (j < refInfo.Length && (index = refInfo[j]) <= i) { if (index == i || index == -1) { reference.Value = args[i]; break; } ++j; } } } } }
public CollocatedExternalFunction(IExternalFunction/*!*/externalFunction, IExternals extManager) { Debug.Assert(externalFunction != null); this.externalFunction = externalFunction; this.extManager = extManager; }