FluentDOM\Query::changeClassString PHP Méthode

changeClassString() private méthode

Adds the specified classes if the switch is TRUE, removes the specified classes if the switch is FALSE, toggles the specified classes if the switch is NULL.
private changeClassString ( string $current, string $toggle, boolean | null $switch ) : FALSE | string
$current string
$toggle string
$switch boolean | null
Résultat FALSE | string
    private function changeClassString($current, $toggle, $switch)
    {
        $currentClasses = array_flip(preg_split('(\\s+)', trim($current), 0, PREG_SPLIT_NO_EMPTY));
        $toggleClasses = array_unique(preg_split('(\\s+)', trim($toggle), 0, PREG_SPLIT_NO_EMPTY));
        $modified = FALSE;
        foreach ($toggleClasses as $class) {
            if (isset($currentClasses[$class]) && (NULL === $switch || FALSE === $switch)) {
                unset($currentClasses[$class]);
                $modified = TRUE;
            } elseif (NULL === $switch || TRUE === $switch) {
                $currentClasses[$class] = TRUE;
                $modified = TRUE;
            }
        }
        return $modified ? implode(' ', array_keys($currentClasses)) : FALSE;
    }