src/Factory.php
public function create($alias, $source, $dependencies = [], $options = [])
    {
        $assetType = isset($options['type']) ? $options['type'] : '';

        if (isset($this->_customTypes[$assetType])) {
            $assetType = $this->_customTypes[$assetType];

        } elseif (is_callable($source)) {
            $assetType = 'Callback';

        } elseif (is_string($source)) {
            $ext = strtolower(FS::ext($source));

            if ($ext === 'js') {
                $assetType = 'JsFile';

            } elseif ($ext === 'css') {
                $assetType = 'CssFile';

            } elseif ($ext === 'less') {
                $assetType = 'LessFile';

            } elseif ($ext === 'jsx') {
                $assetType = 'JsxFile';
            }

        } elseif (is_array($source)) {
            $assetType = 'Collection';
        }

        $className = __NAMESPACE__ . '\\Asset\\' . $assetType;
        if (class_exists($className)) {
            $options = is_array($options) ? new Data($options) : $options;
            return new $className($this->getManager(), $alias, $source, $dependencies, $options);
        }

        throw new Exception('Undefined asset type: ' . print_r($source, true));
    }
public function create($alias, $source, $dependencies = [], $options = [])
    {
        $assetType = isset($options['type']) ? $options['type'] : '';

        if (isset($this->_customTypes[$assetType])) {
            $assetType = $this->_customTypes[$assetType];

        } elseif (is_callable($source)) {
            $assetType = 'Callback';

        } elseif (is_string($source)) {
            $ext = strtolower(FS::ext($source));

            if ($ext === 'js') {
                $assetType = 'JsFile';

            } elseif ($ext === 'css') {
                $assetType = 'CssFile';

            } elseif ($ext === 'less') {
                $assetType = 'LessFile';

            } elseif ($ext === 'jsx') {
                $assetType = 'JsxFile';
            }

        } elseif (is_array($source)) {
            $assetType = 'Collection';
        }

        $className = __NAMESPACE__ . '\\Asset\\' . $assetType;
        if (class_exists($className)) {
            $options = is_array($options) ? new Data($options) : $options;
            return new $className($this->getManager(), $alias, $source, $dependencies, $options);
        }

        throw new Exception('Undefined asset type: ' . print_r($source, true));
    }
public function create ( $ alias , $ source , $ dependencies = [ ] , $ options = [ ] ) { $ assetType = isset ( $ options [ 'type' ] ) ? $ options [ 'type' ] : '' ; if ( isset ( $ this -> _customTypes [ $ assetType ] ) ) { $ assetType = $ this -> _customTypes [ $ assetType ] ; } elseif ( is_callable ( $ source ) ) { $ assetType = 'Callback' ; } elseif ( is_string ( $ source ) ) { $ ext = strtolower ( FS :: ext ( $ source ) ) ; if ( $ ext === 'js' ) { $ assetType = 'JsFile' ; } elseif ( $ ext === 'css' ) { $ assetType = 'CssFile' ; } elseif ( $ ext === 'less' ) { $ assetType = 'LessFile' ; } elseif ( $ ext === 'jsx' ) { $ assetType = 'JsxFile' ; } } elseif ( is_array ( $ source ) ) { $ assetType = 'Collection' ; } $ className = __NAMESPACE__ . '\\Asset\\' . $ assetType ; if ( class_exists ( $ className ) ) { $ options = is_array ( $ options ) ? new Data ( $ options ) : $ options ; return new $ className ( $ this -> getManager ( ) , $ alias , $ source , $ dependencies , $ options ) ; } throw new Exception ( 'Undefined asset type: ' . print_r ( $ source , true ) ) ; }
Create asset instance.

@param string       $alias
@param mixed        $source
@param string|array $dependencies
@param string|array $options
@throws Exception
@return Asset
Create asset instance .