Beispiel #1
0
        public static object GetClassConstant(DTypeDesc type, string constantName, DTypeDesc caller, ScriptContext context)
        {
            if (type == null) return null;

            // lookup the constant desc
            DConstantDesc constant;
            switch (type.GetConstant(new VariableName(constantName), caller, out constant))
            {
                case GetMemberResult.NotFound:
                    {
                        PhpException.Throw(PhpError.Error, CoreResources.GetString("undefined_class_constant",
                            type.MakeFullName(), constantName));
                        return null;
                    }

                case GetMemberResult.BadVisibility:
                    {
                        PhpException.ConstantNotAccessible(
                            constant.DeclaringType.MakeFullName(),
                            constantName,
                            (caller == null ? String.Empty : caller.MakeFullName()),
                            constant.IsProtected);
                        return null;
                    }
            }

            // make sure that the constant has been initialized for this request
            return PhpVariable.Dereference(constant.GetValue(context));
        }