Issue #3027569 by markcarver, just_like_good_vibes: Error: Unsupported operand...

Issue #3027569 by markcarver, just_like_good_vibes: Error: Unsupported operand types during providers JSON discovery
parent 96a19da8
...@@ -16,29 +16,32 @@ define('BOOTSTRAP_CDN_PROVIDER_PATH', 'public://bootstrap/cdn_providers'); ...@@ -16,29 +16,32 @@ define('BOOTSTRAP_CDN_PROVIDER_PATH', 'public://bootstrap/cdn_providers');
* The URI to retrieve JSON from. * The URI to retrieve JSON from.
* @param array $options * @param array $options
* The options to pass to the HTTP client. * The options to pass to the HTTP client.
* @param \Exception|null $exception
* The exception thrown if there was an error, passed by reference.
* *
* @return array|null * @return array
* The requested JSON array or NULL if an error occurred. * The requested JSON array.
*/ */
function _bootstrap_cdn_provider_request_json($uri, array $options = []) { function _bootstrap_cdn_provider_request_json($uri, array $options = array(), &$exception = NULL) {
$json = NULL; $json = array();
$options += [ $options += array(
'method' => 'GET', 'method' => 'GET',
'headers' => [ 'headers' => array(
'User-Agent' => 'Drupal Bootstrap 7.x-3.x (https://www.drupal.org/project/bootstrap)', 'User-Agent' => 'Drupal Bootstrap 7.x-3.x (https://www.drupal.org/project/bootstrap)',
], ),
]; );
try { try {
$response = drupal_http_request($uri, $options); $response = drupal_http_request($uri, $options);
if ($response->code == 200) { if ($response->code == 200) {
$json = drupal_json_decode($response->data); $json = drupal_json_decode($response->data) ?: array();
} }
} }
catch (\Exception $e) { catch (\Exception $e) {
// Intentionally left blank. $exception = $e;
} }
return $json; return $json;
} }
...@@ -80,12 +83,12 @@ function bootstrap_cdn_provider($provider = NULL, $reset = FALSE) { ...@@ -80,12 +83,12 @@ function bootstrap_cdn_provider($provider = NULL, $reset = FALSE) {
), ),
'jsdelivr' => array( 'jsdelivr' => array(
'title' => t('jsDelivr'), 'title' => t('jsDelivr'),
'description' => t('<p><a href="!jsdelivr" target="_blank">jsDelivr</a> is a free multi-CDN infrastructure that uses <a href="!maxcdn" target="_blank">MaxCDN</a>, <a href="!cloudflare" target="_blank">Cloudflare</a> and many others to combine their powers for the good of the open source community... <a href="!jsdelivr_about" target="_blank">read more</a></p>', [ 'description' => t('<p><a href="!jsdelivr" target="_blank">jsDelivr</a> is a free multi-CDN infrastructure that uses <a href="!maxcdn" target="_blank">MaxCDN</a>, <a href="!cloudflare" target="_blank">Cloudflare</a> and many others to combine their powers for the good of the open source community... <a href="!jsdelivr_about" target="_blank">read more</a></p>', array(
'!jsdelivr' => 'https://www.jsdelivr.com', '!jsdelivr' => 'https://www.jsdelivr.com',
'!jsdelivr_about' => 'https://www.jsdelivr.com/about', '!jsdelivr_about' => 'https://www.jsdelivr.com/about',
'!maxcdn' => 'https://www.maxcdn.com', '!maxcdn' => 'https://www.maxcdn.com',
'!cloudflare' => 'https://www.cloudflare.com', '!cloudflare' => 'https://www.cloudflare.com',
]), )),
), ),
); );
...@@ -158,12 +161,12 @@ function bootstrap_bootstrap_cdn_provider_jsdelivr_alter(array &$provider, \stdC ...@@ -158,12 +161,12 @@ function bootstrap_bootstrap_cdn_provider_jsdelivr_alter(array &$provider, \stdC
$provider['versions'] = array(); $provider['versions'] = array();
$provider['themes'] = array(); $provider['themes'] = array();
$json = []; $json = array();
foreach (['bootstrap', 'bootswatch'] as $package) { foreach (array('bootstrap', 'bootswatch') as $package) {
$data = ['name' => $package, 'assets' => []]; $data = array('name' => $package, 'assets' => array());
$latest = '0.0.0'; $latest = '0.0.0';
$versions = []; $versions = array();
$packageJson = _bootstrap_cdn_provider_request_json("https://data.jsdelivr.com/v1/package/npm/$package") + ['versions' => []]; $packageJson = _bootstrap_cdn_provider_request_json("https://data.jsdelivr.com/v1/package/npm/$package") + array('versions' => array());
foreach ($packageJson['versions'] as $key => $version) { foreach ($packageJson['versions'] as $key => $version) {
// Skip irrelevant versions. // Skip irrelevant versions.
if (!preg_match('/^' . substr(BOOTSTRAP_VERSION, 0, 1) . '\.\d+\.\d+$/', $version)) { if (!preg_match('/^' . substr(BOOTSTRAP_VERSION, 0, 1) . '\.\d+\.\d+$/', $version)) {
...@@ -181,7 +184,7 @@ function bootstrap_bootstrap_cdn_provider_jsdelivr_alter(array &$provider, \stdC ...@@ -181,7 +184,7 @@ function bootstrap_bootstrap_cdn_provider_jsdelivr_alter(array &$provider, \stdC
$latest = $version; $latest = $version;
} }
$asset = ['files' => [], 'version' => $version]; $asset = array('files' => array(), 'version' => $version);
foreach ($versionJson['files'] as $file) { foreach ($versionJson['files'] as $file) {
// Skip old bootswatch file structure. // Skip old bootswatch file structure.
if ($package === 'bootswatch' && preg_match('`^/2|/bower_components`', $file['name'], $matches)) { if ($package === 'bootswatch' && preg_match('`^/2|/bower_components`', $file['name'], $matches)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment