Config_Lite::get PHP Méthode

get() public méthode

to get an option by section, call get with a section and the option. To get a global option call get' with null as section. Just call get' without any parameters to get all sections and options. The third parameter is an optional default value to return, if the option is not set, this is practical when dealing with editable files, to keep an application stable with default settings.
public get ( string $sec = null, string $key = null, mixed $default = null ) : mixed
$sec string Section|null - null to get global option
$key string Key
$default mixed return default value if is $key is not set
Résultat mixed
    public function get($sec = null, $key = null, $default = null)
    {
        // handle get without parameters, because we can
        if (null === $sec && null === $key && null === $default) {
            return $this;
            // arrayaccess or $this->sections;
        }
        if (null !== $sec && array_key_exists($sec, $this->sections) && isset($this->sections[$sec][$key])) {
            return $this->sections[$sec][$key];
        }
        // global value
        if (null === $sec && array_key_exists($key, $this->sections)) {
            return $this->sections[$key];
        }
        // section
        if (null === $key && array_key_exists($sec, $this->sections)) {
            return $this->sections[$sec];
        }
        // all sections
        if (null === $sec && array_key_exists($sec, $this->sections)) {
            return $this->sections;
        }
        if (null !== $default) {
            return $default;
        }
        throw new Config_Lite_Exception_UnexpectedValue('key not found, no default value given.');
    }

Usage Example

Exemple #1
0
function parse_ini()
{
    $config = new Config_Lite('config.ini.php');
    $iconVal = array('fa fa-television', 'fa fa-download', 'fa fa-server', 'fa fa-play-circle', 'fa fa-tint', 'fa fa-globe', 'glyphicon glyphicon-calendar', 'glyphicon glyphicon-dashboard', 'glyphicon glyphicon-bullhorn', 'glyphicon glyphicon-search', 'glyphicon glyphicon-headphones');
    $pageOutput = "<form>";
    $pageOutput .= "<div class='applicationContainer'>General:<br>Title: <input type='text' class='general-value' name='general-title' value='" . $config->get('general', 'title') . "'>";
    $pageOutput .= "<div>Enable Dropdown: <input class='general-value' name='general-enabledropdown' type='checkbox' ";
    if ($config->get('general', 'enabledropdown') == true) {
        $pageOutput .= "checked></div></div><br><br>";
    } else {
        $pageOutput .= "></div></div><br>";
    }
    $pageOutput .= "<input type='hidden' class='settings-value' name='settings-enabled' value='true'>" . "<input type='hidden' class='settings-value' name='settings-default' value='false'>" . "<input type='hidden' class='settings-value' name='settings-name' value='Settings'>" . "<input type='hidden' class='settings-value' name='settings-url' value='settings.php'>" . "<input type='hidden' class='settings-value' name='settings-landingpage' value='false'>" . "<input type='hidden' class='settings-value' name='settings-icon' value='fa fa-server'>" . "<input type='hidden' class='settings-value' name='settings-dd' value='true'>";
    $pageOutput .= "<div id='sortable'>";
    foreach ($config as $section => $name) {
        if (is_array($name) && $section != "settings" && $section != "general") {
            $pageOutput .= "<div class='applicationContainer' id='" . $section . "'>\n            <span class='example_icon'></span>";
            foreach ($name as $key => $val) {
                if ($key == "url") {
                    $pageOutput .= "<div>{$key}:<input class='" . $section . "-value' name='" . $section . "-" . $key . "' type='text' value='" . $val . "'></div>";
                } else {
                    if ($key == "name") {
                        $pageOutput .= "<div>{$key}:<input class='appName " . $section . "-value' was='" . $section . "' name='" . $section . "-" . $key . "' type='text' value='" . $val . "'></div>";
                    } else {
                        if ($key == "icon") {
                            $pageOutput .= "<div>{$key}:<select class='iconDD " . $section . "-value' name='" . $section . "-" . $key . "'>";
                            foreach ($iconVal as $icon) {
                                $pageOutput .= "<option value='" . $icon . "'" . ($val == $icon ? " selected>" : ">") . explode(' ', $icon)[1] . "</option>";
                            }
                            $pageOutput .= "</select></div>";
                        } elseif ($key == "default") {
                            $pageOutput .= "<div>{$key}:<input type='radio' class='radio " . $section . "-value' name='" . $section . "-" . $key . "'";
                            if ($val == "true") {
                                $pageOutput .= " checked></div>";
                            } else {
                                $pageOutput .= "></div>";
                            }
                        } else {
                            $pageOutput .= "<div>{$key}:<input class='checkbox " . $section . "-value' name='" . $section . "-" . $key . "' type='checkbox' ";
                            if ($val == "true") {
                                $pageOutput .= " checked></div>";
                            } else {
                                $pageOutput .= "></div>";
                            }
                        }
                    }
                }
            }
            $pageOutput .= "<input type='button' class='removeButton' value='Remove' id='remove-" . $section . "'></div>";
            //Put this back to the left when ajax is ready -- <input type='button' class='saveButton' value='Save' id='save-" . $section . "'>
        }
    }
    $pageOutput .= "</div><div class='center' id='addApplicationButton'>\n                    <input type='button' id='addApplication' value='Add New Application'></div>\n                    <div id='saved'>Saved!</div><div id='removed' class='hidden'></div></form>";
    return $pageOutput;
}
All Usage Examples Of Config_Lite::get