Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpAsset and Google Fonts #859

Open
webbird opened this issue Oct 27, 2017 · 1 comment
Open

HttpAsset and Google Fonts #859

webbird opened this issue Oct 27, 2017 · 1 comment

Comments

@webbird
Copy link

webbird commented Oct 27, 2017

I've encountered an issue when using Bootstrap 4 and Bootswatch Themes. Some themes do an @import loading Google fonts.

Warning: file_get_contents(https://fonts.googleapis.com/css?family=Lato:400,700,400italic): failed to open stream: Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte. in \vendor\kriswallsmith\assetic\src\Assetic\Asset\HttpAsset.php on line 57

XDebug Call Stack:

17 0.5928 4719352 Assetic\AssetWriter->writeManagerAssets( ) ...\Assets.php:103
18 0.5928 4719624 Assetic\AssetWriter->writeAsset( ) ...\AssetWriter.php:53
19 0.5928 4728384 Assetic\Asset\AssetCollection->dump( ) ...\AssetWriter.php:68
20 0.6084 4902648 Assetic\Asset\BaseAsset->dump( ) ...\AssetCollection.php:151
21 0.6084 4902648 Assetic\Asset\FileAsset->load( ) ...\BaseAsset.php:103
22 0.6084 5095224 Assetic\Asset\BaseAsset->doLoad( ) ...\FileAsset.php:64
23 0.6084 5095496 Assetic\Filter\FilterCollection->filterLoad( ) ...\BaseAsset.php:94
24 0.6084 5095496 Assetic\Filter\CssImportFilter->filterLoad( ) ...\FilterCollection.php:62
25 0.6084 5096016 Assetic\Filter\BaseCssFilter->filterImports( ) ...\CssImportFilter.php:92
26 0.6084 5096016 Assetic\Util\CssUtils::filterImports( ) ...\BaseCssFilter.php:44
27 0.6084 5096504 Assetic\Util\CssUtils::filterCommentless( ) ...\CssUtils.php:76
28 0.6084 5290304 call_user_func:{Assetic\Util\CssUtils.php:109} ( ) ...\CssUtils.php:109
29 0.6084 5290304 Assetic\Util\CssUtils::Assetic\Util{closure}( ) ...\CssUtils.php:109
30 0.6084 5290304 preg_replace_callback ( ) ...\CssUtils.php:75
31 0.6084 5290896 Assetic\Filter\CssImportFilter->Assetic\Filter{closure}( ) ...\CssUtils.php:75
32 0.6084 5305896 Assetic\Asset\BaseAsset->dump( ) ...\CssImportFilter.php:85
33 0.6084 5305896 Assetic\Asset\HttpAsset->load( ) ...\BaseAsset.php:103
34 0.6084 5305896 file_get_contents ( ) ...\HttpAsset.php:57

I am going to change / extend the code to use curl instead... has anyone already done it?

@webbird
Copy link
Author

webbird commented Oct 27, 2017

This works for me:

public function load(FilterInterface $additionalFilter = null)
{
    if(function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_URL, VarUtils::resolve($this->sourceUrl, $this->getVars(), $this->getValues()));
        curl_setopt($ch, CURLOPT_REFERER, VarUtils::resolve($this->sourceUrl, $this->getVars(), $this->getValues()));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_PROXY, '<proxy>');
        curl_setopt($ch, CURLOPT_PROXYPORT, '<port>');
        $content = curl_exec($ch);
        curl_close($ch);
    } else {
        $content = @file_get_contents(
            VarUtils::resolve($this->sourceUrl, $this->getVars(), $this->getValues())
        );
    }

    if (false === $content && !$this->ignoreErrors) {
        throw new \RuntimeException(sprintf('Unable to load asset from URL "%s"', $this->sourceUrl));
    }

    $this->doLoad($content, $additionalFilter);
}

As I am behind a proxy, I'd like to add appropriate options. Where should they be placed? AssetFactory.php? Function setProxy()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant