public static function createObject($type, $defaultClass, $instanceOf = false, $param = [])
    {
        if (is_string($type)) {
            $type = ['class' => $type];
        }
        if (is_array($type) && ! isset($type['class']) && !empty($defaultClass)) {
            $type['class'] = $defaultClass;
        }
        if ( ! is_object($type)) {
            $type = Yii::createObject($type, $param);
        }
        if ($instanceOf === true) {
            $instanceOf = $defaultClass;
        }
        if ($instanceOf && ! $type instanceof $instanceOf) {
            throw new InvalidArgumentException(get_class($type) . " not instance of $instanceOf");
        }

        return $type;
    }