protected function _hasReference($c, $link, $defaults = []) : Reference
    {
        if (!is_array($defaults)) {
            $defaults = ['model' => $defaults ?: 'Model_'.$link];
        } elseif (isset($defaults[0])) {
            $defaults['model'] = $defaults[0];
            unset($defaults[0]);
        }

        $defaults[0] = $link;

        $obj = $this->factory($c, $defaults);

        // if reference with such name already exists, then throw exception
        if ($this->hasElement($name = $obj->getDesiredName())) {
            throw new Exception([
                'Reference with such name already exists',
                'name'     => $name,
                'link'     => $link,
                'defaults' => $defaults,
            ]);
        }

        return $this->add($obj);
    }
protected function _hasReference($c, $link, $defaults = []) : Reference
    {
        if (!is_array($defaults)) {
            $defaults = ['model' => $defaults ?: 'Model_'.$link];
        } elseif (isset($defaults[0])) {
            $defaults['model'] = $defaults[0];
            unset($defaults[0]);
        }

        $defaults[0] = $link;

        $obj = $this->factory($c, $defaults);

        // if reference with such name already exists, then throw exception
        if ($this->hasElement($name = $obj->getDesiredName())) {
            throw new Exception([
                'Reference with such name already exists',
                'name'     => $name,
                'link'     => $link,
                'defaults' => $defaults,
            ]);
        }

        return $this->add($obj);
    }
protected function _hasReference ( $ c , $ link , $ defaults = [ ] ) : Reference { if ( ! is_array ( $ defaults ) ) { $ defaults = [ 'model' => $ defaults ? : 'Model_' . $ link ] ; } elseif ( isset ( $ defaults [ 0 ] ) ) { $ defaults [ 'model' ] = $ defaults [ 0 ] ; unset ( $ defaults [ 0 ] ) ; } $ defaults [ 0 ] = $ link ; $ obj = $ this -> factory ( $ c , $ defaults ) ; // if reference with such name already exists, then throw exception if ( $ this -> hasElement ( $ name = $ obj -> getDesiredName ( ) ) ) { throw new Exception ( [ 'Reference with such name already exists' , 'name' => $ name , 'link' => $ link , 'defaults' => $ defaults , ] ) ; } return $ this -> add ( $ obj ) ; }
Private method.

@param string         $c        Class name
@param string         $link     Link
@param array|callable $defaults Properties which we will pass to Reference object constructor

@throws Exception
@throws \atk4\core\Exception

@return Reference
Private method .