src/polary/base/Object.php
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;
    }
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;
    }
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 ; }
Create object with set default class and check parent class.

@param array|string|callable $type
@param string                $defaultClass
@param string|bool           $instanceOf
@param array                 $param
@return object
Create object with set default class and check parent class .