Beispiel #1
0
        /// <summary>
        /// Formats a state of the specified option into <see cref="PhpArray"/>.
        /// </summary>
        /// <param name="flags">The option's flag.</param>
        /// <param name="defaultValue">A default value of the option.</param>
        /// <param name="localValue">A script local value of the option.</param>
        /// <returns>An array containig keys <c>"global_value"</c>, <c>"local_value"</c>, <c>"access"</c>.</returns>
        private static PhpArray FormatOptionState(IniFlags flags, object defaultValue, object localValue)
        {
            PhpArray result = new PhpArray(0, 3);

            // default value:
            result.Add("global_value", Convert.ObjectToString(defaultValue));

            // local value:
            result.Add("local_value", Convert.ObjectToString(localValue));

            // accessibility:
            result.Add("access", (int)((flags & IniFlags.Local) != 0 ? IniAccessability.Local : IniAccessability.Global));

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Tries to get, set, or restore an option given its PHP name and value.
        /// </summary>
        /// <param name="name">The option name.</param>
        /// <param name="value">The option new value if applicable.</param>
        /// <param name="action">The action to be taken.</param>
        /// <param name="error"><B>true</B>, on failure.</param>
        /// <returns>The option old value.</returns>
        /// <exception cref="PhpException">The option not supported (Warning).</exception>
        /// <exception cref="PhpException">The option is read only but action demands write access (Warning).</exception>
        internal static object TryGetSetRestore(string name, object value, IniAction action, out bool error)
        {
            Debug.Assert(name != null);
            error = true;

            IniOptions.OptionDefinition option = GetOption(name);

            // option not found:
            if (option == null)
            {
                // check for options in native extensions:
                string result = null;
                switch (action)
                {
                case IniAction.Get: error = !Externals.IniGet(name, out result); break;

                case IniAction.Set: error = !Externals.IniSet(name, Convert.ObjectToString(value), out result); break;

                case IniAction.Restore: error = !Externals.IniRestore(name); break;
                }
                if (error)
                {
                    PhpException.Throw(PhpError.Warning, LibResources.GetString("unknown_option", name));
                }
                return(result);
            }

            // the option is known but not supported:
            if ((option.Flags & IniFlags.Supported) == 0)
            {
                PhpException.Throw(PhpError.Warning, LibResources.GetString("option_not_supported", name));
                return(null);
            }

            // the option is global thus cannot be changed:
            if ((option.Flags & IniFlags.Local) == 0 && action != IniAction.Get)
            {
                PhpException.Throw(PhpError.Warning, LibResources.GetString("option_readonly", name));
                return(null);
            }

            error = false;
            return(option.Gsr(Configuration.Local, name, value, action));
        }