Esempio n. 1
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)
            {
                PhpException.Throw(PhpError.Warning, LibResources.GetString("unknown_option", name));
                return(null);
            }

            // 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));
        }
Esempio n. 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));
        }