Merge pull request #1771 from bolt/bugfix/unsplash-image-fixtures

Unsplash images fixtures work even if ssl verification fails
This commit is contained in:
Bob den Otter
2020-08-26 12:28:26 +02:00
committed by GitHub
3 changed files with 20 additions and 2 deletions
+3
View File
@@ -211,3 +211,6 @@ wysiwyg:
# Enforcing the use of SSL. If set, all pages will enforce an SSL connection,
# and redirect to HTTPS if you attempt to visit plain HTTP pages.
# enforce_ssl: true
curl_options:
verify_peer: false
@@ -47,6 +47,12 @@ class GeneralParser extends BaseParser
$general['date_format'] = 'F j, Y H:i';
}
if (! isset($general['curl_options'])) {
$general['curl_options'] = [
'verify_peer' => true,
];
}
return new Collection($general);
}
+11 -2
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Bolt\DataFixtures;
use Bolt\Configuration\Config;
use Bolt\Configuration\FileLocations;
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
use Doctrine\Persistence\ObjectManager;
@@ -23,7 +24,10 @@ class ImageFetchFixtures extends BaseFixture implements FixtureGroupInterface
private const AMOUNT = 10;
private const MAX_AMOUNT = 50;
public function __construct(FileLocations $fileLocations)
/** @var array */
private $curlOptions;
public function __construct(FileLocations $fileLocations, Config $config)
{
$this->urls = new Collection([
'https://source.unsplash.com/1280x1024/?business,workspace,interior/',
@@ -32,6 +36,8 @@ class ImageFetchFixtures extends BaseFixture implements FixtureGroupInterface
'https://source.unsplash.com/1280x1024/?technology/',
]);
$this->curlOptions = $config->get('general/curl_options', []);
$this->fileLocations = $fileLocations;
}
@@ -69,7 +75,10 @@ class ImageFetchFixtures extends BaseFixture implements FixtureGroupInterface
$client = HttpClient::create();
$resource = fopen($outputPath . $filename, 'w');
fwrite($resource, $client->request('GET', $url)->getContent());
$image = $client->request('GET', $url, $this->curlOptions)->getContent();
fwrite($resource, $image);
fclose($resource);
$progressBar->advance();