igaster / laravel-theme

Theme support for Laravel
MIT License
520 stars 113 forks source link

External Asset URL S3/CDN Support #8

Closed kristopherchun closed 9 years ago

kristopherchun commented 9 years ago

Have it return the the assetPath if it's an external URL to support s3 or cdn as the base path. This may not be the best solution, but it works for me :)

    // gaster/laravel-theme/src/Theme.php

    public function url($url){
        if(preg_match('/^((http(s?):)?\/\/)/i',$url))
            return $url;

        if(preg_match('/^((http(s?):)?\/\/)/i',$this->assetPath))
            return $this->assetPath.'/'.ltrim($url, '/');

        $fullUrl = (empty($this->assetPath) ? '' : '/').$this->assetPath.'/'.ltrim($url, '/');
    }
igaster commented 9 years ago

I think it's OK to ovveride asset discovery when they are stored in an external URL. Looking up for files that are on a remote server would be time consuming.

I will come back with a caching mechanism to support S3 etc ASAP, but until then your solution is OK. I will intergrate it to the next version...

igaster commented 9 years ago

OK pushed into v1.0.13. Some testing is still needed... A better solution (caching remote paths?) will be investigated in future releases.. Thanks.

kristopherchun commented 9 years ago

That is great! Thank you! :+1: