public function getInstance(string $class, $element_id)
    {
        if (!is_a($class, Hierarchy::class, true))
            throw new TypeError("Not a subclass of Hierarchy: $class");

        if (is_object($element_id) && get_class($element_id) === $class)
            return $element_id;

        if (!is_scalar($element_id))
            throw new TypeError("Element-ID must be a scalar");

        if (!$this->hasInstance($class, $element_id))
        {
            $root = $class::getRootName();
            if ($element_id === $root)
                $this->hierarchy[$class][$root] = new $class($this, $root);
            else
                throw new Exception("Element-ID '{$element_id}' is unknown for {$class}");
        }

        return $this->hierarchy[$class][$element_id];
    }
public function getInstance(string $class, $element_id)
    {
        if (!is_a($class, Hierarchy::class, true))
            throw new TypeError("Not a subclass of Hierarchy: $class");

        if (is_object($element_id) && get_class($element_id) === $class)
            return $element_id;

        if (!is_scalar($element_id))
            throw new TypeError("Element-ID must be a scalar");

        if (!$this->hasInstance($class, $element_id))
        {
            $root = $class::getRootName();
            if ($element_id === $root)
                $this->hierarchy[$class][$root] = new $class($this, $root);
            else
                throw new Exception("Element-ID '{$element_id}' is unknown for {$class}");
        }

        return $this->hierarchy[$class][$element_id];
    }
public function getInstance ( string $ class , $ element_id ) { if ( ! is_a ( $ class , Hierarchy :: class , true ) ) throw new TypeError ( "Not a subclass of Hierarchy: $class" ) ; if ( is_object ( $ element_id ) && get_class ( $ element_id ) === $ class ) return $ element_id ; if ( ! is_scalar ( $ element_id ) ) throw new TypeError ( "Element-ID must be a scalar" ) ; if ( ! $ this -> hasInstance ( $ class , $ element_id ) ) { $ root = $ class :: getRootName ( ) ; if ( $ element_id === $ root ) $ this -> hierarchy [ $ class ] [ $ root ] = new $ class ( $ this , $ root ) ; else throw new Exception ( "Element-ID '{$element_id}' is unknown for {$class}" ) ; } return $ this -> hierarchy [ $ class ] [ $ element_id ] ; }
Get an hierarchy element by specifying its ID
Get an hierarchy element by specifying its ID