kartik\tree\TreeView::usesTrait PHP Méthode

usesTrait() protected static méthode

Check if the trait is used by a specific class or recursively by any of the parent classes or parent traits
protected static usesTrait ( string $class, string $trait, boolean $autoload = false ) : boolean
$class string the class name to check
$trait string the trait class name
$autoload boolean whether to autoload the class
Résultat boolean whether the class has used the trait
    protected static function usesTrait($class, $trait, $autoload = false)
    {
        $traits = [];
        do {
            $traits = array_merge(class_uses($class, $autoload), $traits);
            if (in_array($trait, $traits)) {
                return true;
            }
        } while ($class = get_parent_class($class));
        $traitsToSearch = $traits;
        while (!empty($traitsToSearch)) {
            $newTraits = class_uses(array_pop($traitsToSearch), $autoload);
            $traits = array_merge($newTraits, $traits);
            if (in_array($trait, $traits)) {
                return true;
            }
            $traitsToSearch = array_merge($newTraits, $traitsToSearch);
        }
        foreach ($traits as $t => $str) {
            $traits = array_merge(class_uses($t, $autoload), $traits);
            if (in_array($trait, $traits)) {
                return true;
            }
        }
        return false;
    }