@ 2015-04-16T10:01:50Z <?php
function mergeAttachments($a, $b) {
// If both #attached arrays contain drupalSettings, then merge them
// correctly; adding the same settings multiple times needs to behave
// idempotently.
if (!empty($a['drupalSettings']) && !empty($b['drupalSettings'])) {
$drupalSettings = NestedArray::mergeDeepArray(array($a['drupalSettings'], $b['drupalSettings']), TRUE);
// No need for re-merging them.
unset($a['drupalSettings']);
unset($b['drupalSettings']);
}
// Apply the normal merge.
$a = NestedArray::mergeDeepArray(array($a, $b));
if (isset($drupalSettings)) {
// Save the custom merge for the drupalSettings.
$a['drupalSettings'] = $drupalSettings;
}
return $a;
}
function mergeAttachmentsOld($a, $b) {
if (!empty($a['drupalSettings']) && !empty($b['drupalSettings'])) {
$a['drupalSettings'] = mergeDeepArray([$a['drupalSettings'], $b['drupalSettings']], TRUE);
unset($b['drupalSettings']);
}
return mergeDeep($a, $b);
}
function mergeDeepArray($arrays, $preserve_integer_keys = FALSE) {
$result = array();
foreach ($arrays as $array) {
foreach ($array as $key => $value) {
// Renumber integer keys as array_merge_recursive() does unless
// $preserve_integer_keys is set to TRUE. Note that PHP automatically
// converts array keys that are integer strings (e.g., '1') to integers.
if (is_integer($key) && !$preserve_integer_keys) {
$result[] = $value;
}
// Recurse when both values are arrays.
elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {
$result[$key] = mergeDeepArray(array($result[$key], $value), $preserve_integer_keys);
}
// Otherwise, use the latter value, overriding any previous value.
else {
$result[$key] = $value;
}
}
}
return $result;
}
function mergeDeep() {
return mergeDeepArray(func_get_args());
}
for($i = 0; $i <= 100000; $i++) {
$a['#attached'] = array(
'library' => array(
'core/drupal',
'core/drupalSettings',
),
);
$b['#attached'] = array(
'library' => array(
'core/jquery',
),
);
mergeAttachments($a['#attached'], $b['#attached']);
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for git.master , git.master_jit , rfc.property-hooks Fatal error: Uncaught Error: Class "NestedArray" not found in /in/3MJVC:14
Stack trace:
#0 /in/3MJVC(69): mergeAttachments(Array, Array)
#1 {main}
thrown in /in/3MJVC on line 14
Process exited with code 255 . This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches Archived branches Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:dark mode live preview
64.02 ms | 401 KiB | 8 Q