public override string GetPhpScriptReferenceCode(StringCollection code)
 {
     if (this.Method == null)
     {
         DesignUtil.WriteToOutputWindowAndLog("GetPhpScriptReferenceCode failed. Method not found. ParameterID:{0}, ActionID:{1}, ClassId:{2}", this.ParameterID, ActionId, this.ClassId);
     }
     else
     {
         SubMethodInfoPointer smi = this.Method as SubMethodInfoPointer;
         if (smi == null)
         {
             MethodClass mc = this.Method as MethodClass;
             if (ActionId != 0 && mc != null && mc.ActionList != null)
             {
                 IAction act = mc.ActionList.GetActionById(ActionId);
                 if (act != null)
                 {
                     smi = act.ActionMethod as SubMethodInfoPointer;
                 }
             }
         }
         if (smi == null)
         {
             DesignUtil.WriteToOutputWindowAndLog("GetPhpScriptReferenceCode failed. method [{0}][{1}] found by parameter [{2}] is not a SubMethodInfoPointer", this.Method.MethodName, this.Method.ObjectKey, this.ParameterID);
         }
         else
         {
             if (this.ActionBranch == null)
             {
                 MethodClass mc = this.Method as MethodClass;
                 if (mc != null && mc.SubMethod != null && mc.SubMethod.Count > 0)
                 {
                     IMethod0           m0  = mc.SubMethod.Peek();
                     AB_SubMethodAction asa = m0 as AB_SubMethodAction;
                     if (asa != null)
                     {
                         this.SetActionBranch(asa);
                     }
                 }
             }
             if (this.ActionBranch == null)
             {
                 DesignUtil.WriteToOutputWindowAndLog("GetPhpScriptReferenceCode failed. parameter [{2}] for method [{0}][{1}] missing ActionBranch", this.Method.MethodName, this.Method.ObjectKey, this.ParameterID);
             }
             else
             {
                 SubMethodInfo mi     = smi.MethodInformation as SubMethodInfo;
                 string        target = smi.Owner.GetPhpScriptReferenceCode(code);
                 return(string.Format(CultureInfo.InvariantCulture,
                                      "{0}[{1}]", target, mi.GetIndexCodePHP(smi, this.ActionBranch.BranchId)));
             }
         }
     }
     return(CodeName);
 }
コード例 #2
0
        public override bool OnExportPhpScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data)
        {
            bool bRet;

            if (_actionData == null)
            {
                _actionData = (ActionSubMethod)this.Method.GetActionInstance(_actId.ActionId);
            }
            SubMethodInfoPointer smi = _actionData.ActionMethod as SubMethodInfoPointer;
            SubMethodInfo        mi  = smi.MethodInformation as SubMethodInfo;

            if (mi == null)
            {
                return(false);
            }
            if (mi.IsForeach)
            {
                ParameterClassSubMethod p  = mi.GetParameterType(0, smi, this);
                StringBuilder           sb = new StringBuilder();
                string         s1          = smi.Owner.CodeName;
                IObjectPointer op          = smi.Owner;
                sb.Append(s1);
                while (!(op is ILocalvariable) && op.Owner != null && op.Owner.Owner != null)
                {
                    if (string.CompareOrdinal(s1, op.Owner.CodeName) != 0)
                    {
                        s1 = op.Owner.CodeName;
                        sb.Insert(0, "->");
                        sb.Insert(0, s1);
                    }
                    op = op.Owner;
                }
                if (op is ILocalvariable || op.Owner is ILocalvariable)
                {
                }
                else
                {
                    sb.Insert(0, "$this->");
                }
                s1 = sb.ToString();
                string indents = Indentation.GetIndent();
                string s0      = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                               "\r\n{2}foreach ({0} as {1}) {{\r\n", s1, p.CodeName, indents);
                methodCode.Add(s0);
                //
                Method.SubMethod.Push(this);
                data.AddSubMethod(this);
                Indentation.IndentIncrease();
                bRet = base.OnExportPhpScriptCode(previousAction, nextAction, jsCode, methodCode, data);
                Indentation.IndentDecrease();
                Method.SubMethod.Pop();
                //
                methodCode.Add(indents);
                methodCode.Add("}\r\n");
            }
            else
            {
                string         indents = Indentation.GetIndent();
                StringBuilder  sb      = new StringBuilder();
                string         s1      = smi.Owner.CodeName;
                IObjectPointer op      = smi.Owner;
                sb.Append(s1);
                while (!(op is ILocalvariable) && op.Owner != null && op.Owner.Owner != null)
                {
                    if (string.CompareOrdinal(s1, op.Owner.CodeName) != 0)
                    {
                        s1 = op.Owner.CodeName;
                        sb.Insert(0, "->");
                        sb.Insert(0, s1);
                    }
                    op = op.Owner;
                }
                if (op is ILocalvariable)
                {
                }
                else
                {
                    sb.Insert(0, "$this->");
                }
                s1 = sb.ToString();

                ParameterClassSubMethod p = mi.GetParameterType(1, smi, this);
                p.ParameterID = _actionData.ParameterValues[1].ParameterID;
                string v  = p.CodeName;
                string s0 = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                          "\r\n{3}foreach ({0} as {1} => {2} ) {{\r\n", s1, mi.GetIndexCodePHP(smi, this.BranchId), v, indents);
                methodCode.Add(s0);
                Method.SubMethod.Push(this);
                data.AddSubMethod(this);
                //
                Indentation.IndentIncrease();
                bRet = base.OnExportPhpScriptCode(previousAction, nextAction, jsCode, methodCode, data);
                Method.SubMethod.Pop();
                //
                Indentation.IndentDecrease();
                methodCode.Add(indents);
                methodCode.Add("}\r\n");
            }

            return(bRet);
        }