Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -49,7 +49,7 @@ class ArgumentsResolver implements ArgumentsResolverInterface {
* {@inheritdoc}
*/
public function getArguments(callable $callable) {
$arguments = array();
$arguments = [];
foreach ($this->getReflector($callable)->getParameters() as $parameter) {
$arguments[] = $this->getArgument($parameter);
}

View file

@ -56,11 +56,11 @@ class Color {
$c = hexdec($hex);
return array(
return [
'red' => $c >> 16 & 0xFF,
'green' => $c >> 8 & 0xFF,
'blue' => $c & 0xFF,
);
];
}
/**

View file

@ -19,7 +19,8 @@ class Crypt {
*
* In PHP 7 and up, this uses the built-in PHP function random_bytes().
* In older PHP versions, this uses the random_bytes() function provided by
* the random_compat library.
* the random_compat library, or the fallback hash-based generator from Drupal
* 7.x.
*
* @param int $count
* The number of characters (bytes) to return in the string.
@ -28,7 +29,43 @@ class Crypt {
* A randomly generated string.
*/
public static function randomBytes($count) {
return random_bytes($count);
try {
return random_bytes($count);
}
catch (\Exception $e) {
// $random_state does not use drupal_static as it stores random bytes.
static $random_state, $bytes;
// If the compatibility library fails, this simple hash-based PRNG will
// generate a good set of pseudo-random bytes on any system.
// Note that it may be important that our $random_state is passed
// through hash() prior to being rolled into $output, that the two hash()
// invocations are different, and that the extra input into the first one
// - the microtime() - is prepended rather than appended. This is to avoid
// directly leaking $random_state via the $output stream, which could
// allow for trivial prediction of further "random" numbers.
if (strlen($bytes) < $count) {
// Initialize on the first call. The $_SERVER variable includes user and
// system-specific information that varies a little with each page.
if (!isset($random_state)) {
$random_state = print_r($_SERVER, TRUE);
if (function_exists('getmypid')) {
// Further initialize with the somewhat random PHP process ID.
$random_state .= getmypid();
}
$bytes = '';
// Ensure mt_rand() is reseeded before calling it the first time.
mt_srand();
}
do {
$random_state = hash('sha256', microtime() . mt_rand() . $random_state);
$bytes .= hash('sha256', mt_rand() . $random_state, TRUE);
} while (strlen($bytes) < $count);
}
$output = substr($bytes, 0, $count);
$bytes = substr($bytes, $count);
return $output;
}
}
/**

View file

@ -25,7 +25,7 @@ class DiffArray {
* in array2.
*/
public static function diffAssocRecursive(array $array1, array $array2) {
$difference = array();
$difference = [];
foreach ($array1 as $key => $value) {
if (is_array($value)) {

View file

@ -14,7 +14,7 @@ class Html {
*
* @var array
*/
protected static $classes = array();
protected static $classes = [];
/**
* An array of the initial IDs used in one request.
@ -89,13 +89,13 @@ class Html {
* @return string
* The cleaned identifier.
*/
public static function cleanCssIdentifier($identifier, array $filter = array(
public static function cleanCssIdentifier($identifier, array $filter = [
' ' => '-',
'_' => '-',
'/' => '-',
'[' => '-',
']' => '',
)) {
]) {
// We could also use strtr() here but its much slower than str_replace(). In
// order to keep '__' to stay '__' we first replace it with a different
// placeholder after checking that it is not defined as a filter.
@ -120,10 +120,10 @@ class Html {
// We strip out any character not in the above list.
$identifier = preg_replace('/[^\x{002D}\x{0030}-\x{0039}\x{0041}-\x{005A}\x{005F}\x{0061}-\x{007A}\x{00A1}-\x{FFFF}]/u', '', $identifier);
// Identifiers cannot start with a digit, two hyphens, or a hyphen followed by a digit.
$identifier = preg_replace(array(
$identifier = preg_replace([
'/^[0-9]/',
'/^(-[0-9])|^(--)/'
), array('_', '__'), $identifier);
], ['_', '__'], $identifier);
return $identifier;
}
@ -176,7 +176,7 @@ class Html {
// @todo Remove all that code once we switch over to random IDs only,
// see https://www.drupal.org/node/1090592.
if (!isset(static::$seenIdsInit)) {
static::$seenIdsInit = array();
static::$seenIdsInit = [];
}
if (!isset(static::$seenIds)) {
static::$seenIds = static::$seenIdsInit;
@ -279,7 +279,7 @@ EOD;
// PHP's \DOMDocument serialization adds extra whitespace when the markup
// of the wrapping document contains newlines, so ensure we remove all
// newlines before injecting the actual HTML body to be processed.
$document = strtr($document, array("\n" => '', '!html' => $html));
$document = strtr($document, ["\n" => '', '!html' => $html]);
$dom = new \DOMDocument();
// Ignore warnings during HTML soup loading.

View file

@ -150,7 +150,7 @@ class NestedArray {
// PHP auto-creates container arrays and NULL entries without error if $ref
// is NULL, but throws an error if $ref is set, but not an array.
if ($force && isset($ref) && !is_array($ref)) {
$ref = array();
$ref = [];
}
$ref = &$ref[$parent];
}
@ -322,7 +322,7 @@ class NestedArray {
* @see NestedArray::mergeDeep()
*/
public static function mergeDeepArray(array $arrays, $preserve_integer_keys = FALSE) {
$result = array();
$result = [];
foreach ($arrays as $array) {
foreach ($array as $key => $value) {
// Renumber integer keys as array_merge_recursive() does unless
@ -333,7 +333,7 @@ class NestedArray {
}
// Recurse when both values are arrays.
elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {
$result[$key] = self::mergeDeepArray(array($result[$key], $value), $preserve_integer_keys);
$result[$key] = self::mergeDeepArray([$result[$key], $value], $preserve_integer_keys);
}
// Otherwise, use the latter value, overriding any previous value.
else {

View file

@ -24,14 +24,14 @@ class Random {
*
* @var array
*/
protected $strings = array();
protected $strings = [];
/**
* A list of unique names generated by name().
*
* @var array
*/
protected $names = array();
protected $names = [];
/**
* Generates a random string of ASCII characters of codes 32 to 126.
@ -141,9 +141,9 @@ class Random {
public function word($length) {
mt_srand((double) microtime() * 1000000);
$vowels = array("a", "e", "i", "o", "u");
$cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr",
"cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl", "sh");
$vowels = ["a", "e", "i", "o", "u"];
$cons = ["b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr",
"cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl", "sh"];
$num_vowels = count($vowels);
$num_cons = count($cons);
@ -190,7 +190,7 @@ class Random {
* Nonsense latin words which form sentence(s).
*/
public function sentences($min_word_count, $capitalize = FALSE) {
$dictionary = array("abbas", "abdo", "abico", "abigo", "abluo", "accumsan",
$dictionary = ["abbas", "abdo", "abico", "abigo", "abluo", "accumsan",
"acsi", "ad", "adipiscing", "aliquam", "aliquip", "amet", "antehabeo",
"appellatio", "aptent", "at", "augue", "autem", "bene", "blandit",
"brevitas", "caecus", "camur", "capto", "causa", "cogo", "comis",
@ -219,7 +219,7 @@ class Random {
"utrum", "uxor", "valde", "valetudo", "validus", "vel", "velit",
"veniam", "venio", "vereor", "vero", "verto", "vicis", "vindico",
"virtus", "voco", "volutpat", "vulpes", "vulputate", "wisi", "ymo",
"zelus");
"zelus"];
$dictionary_flipped = array_flip($dictionary);
$greeking = '';

View file

@ -25,7 +25,7 @@ class Tags {
preg_match_all($regexp, $tags, $matches);
$typed_tags = array_unique($matches[1]);
$tags = array();
$tags = [];
foreach ($typed_tags as $tag) {
// If a user has escaped a term (to demonstrate that it is a group,
// or includes a comma or quote character), we remove the escape
@ -65,7 +65,7 @@ class Tags {
* The imploded string.
*/
public static function implode($tags) {
$encoded_tags = array();
$encoded_tags = [];
foreach ($tags as $tag) {
$encoded_tags[] = self::encode($tag);
}

View file

@ -9,7 +9,7 @@ namespace Drupal\Component\Utility;
*/
class Timer {
static protected $timers = array();
static protected $timers = [];
/**
* Starts the timer with the specified name.

View file

@ -125,7 +125,7 @@ EOD;
* The new status of multibyte support.
*/
public static function setStatus($status) {
if (!in_array($status, array(static::STATUS_SINGLEBYTE, static::STATUS_MULTIBYTE, static::STATUS_ERROR))) {
if (!in_array($status, [static::STATUS_SINGLEBYTE, static::STATUS_MULTIBYTE, static::STATUS_ERROR])) {
throw new \InvalidArgumentException('Invalid status value for unicode support.');
}
static::$status = $status;
@ -189,7 +189,7 @@ EOD;
* The name of the encoding, or FALSE if no byte order mark was present.
*/
public static function encodingFromBOM($data) {
static $bomMap = array(
static $bomMap = [
"\xEF\xBB\xBF" => 'UTF-8',
"\xFE\xFF" => 'UTF-16BE',
"\xFF\xFE" => 'UTF-16LE',
@ -200,7 +200,7 @@ EOD;
"\x2B\x2F\x76\x2B" => 'UTF-7',
"\x2B\x2F\x76\x2F" => 'UTF-7',
"\x2B\x2F\x76\x38\x2D" => 'UTF-7',
);
];
foreach ($bomMap as $bom => $encoding) {
if (strpos($data, $bom) === 0) {
@ -542,7 +542,7 @@ EOD;
}
if ($wordsafe) {
$matches = array();
$matches = [];
// Find the last word boundary, if there is one within $min_wordsafe_length
// to $max_length characters. preg_match() is always greedy, so it will
// find the longest string possible.

View file

@ -14,7 +14,7 @@ class UrlHelper {
*
* @var array
*/
protected static $allowedProtocols = array('http', 'https');
protected static $allowedProtocols = ['http', 'https'];
/**
* Parses an array into a valid, rawurlencoded query string.
@ -43,7 +43,7 @@ class UrlHelper {
* @ingroup php_wrappers
*/
public static function buildQuery(array $query, $parent = '') {
$params = array();
$params = [];
foreach ($query as $key => $value) {
$key = ($parent ? $parent . '[' . rawurlencode($key) . ']' : rawurlencode($key));
@ -79,7 +79,7 @@ class UrlHelper {
* @return
* An array containing query parameters.
*/
public static function filterQueryParameters(array $query, array $exclude = array(), $parent = '') {
public static function filterQueryParameters(array $query, array $exclude = [], $parent = '') {
// If $exclude is empty, there is nothing to filter.
if (empty($exclude)) {
return $query;
@ -88,7 +88,7 @@ class UrlHelper {
$exclude = array_flip($exclude);
}
$params = array();
$params = [];
foreach ($query as $key => $value) {
$string_key = ($parent ? $parent . '[' . $key . ']' : $key);
if (isset($exclude[$string_key])) {
@ -134,11 +134,11 @@ class UrlHelper {
* @ingroup php_wrappers
*/
public static function parse($url) {
$options = array(
$options = [
'path' => NULL,
'query' => array(),
'query' => [],
'fragment' => '',
);
];
// External URLs: not using parse_url() here, so we do not have to rebuild
// the scheme, host, and path without having any use for it.
@ -294,7 +294,7 @@ class UrlHelper {
* @param array $protocols
* An array of protocols, for example http, https and irc.
*/
public static function setAllowedProtocols(array $protocols = array()) {
public static function setAllowedProtocols(array $protocols = []) {
static::$allowedProtocols = $protocols;
}

View file

@ -36,7 +36,7 @@ class UserAgent {
* The selected language code or FALSE if no valid language can be
* identified.
*/
public static function getBestMatchingLangcode($http_accept_language, $langcodes, $mappings = array()) {
public static function getBestMatchingLangcode($http_accept_language, $langcodes, $mappings = []) {
// The Accept-Language header contains information about the language
// preferences configured in the user's user agent / operating system.
// RFC 2616 (section 14.4) defines the Accept-Language header as follows:
@ -44,7 +44,7 @@ class UserAgent {
// 1#( language-range [ ";" "q" "=" qvalue ] )
// language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )
// Samples: "hu, en-us;q=0.66, en;q=0.33", "hu,en-us;q=0.5"
$ua_langcodes = array();
$ua_langcodes = [];
if (preg_match_all('@(?<=[, ]|^)([a-zA-Z-]+|\*)(?:;q=([0-9.]+))?(?:$|\s*,\s*)@', trim($http_accept_language), $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
if ($mappings) {

View file

@ -43,7 +43,7 @@ class Variable {
// If the string contains a line break or a single quote, use the
// double quote export mode. Encode backslash, dollar symbols, and
// double quotes and transform some common control characters.
$var = str_replace(array('\\', '$', '"', "\n", "\r", "\t"), array('\\\\', '\$', '\"', '\n', '\r', '\t'), $var);
$var = str_replace(['\\', '$', '"', "\n", "\r", "\t"], ['\\\\', '\$', '\"', '\n', '\r', '\t'], $var);
$output = '"' . $var . '"';
}
else {

View file

@ -16,7 +16,7 @@ class Xss {
*
* @see \Drupal\Component\Utility\Xss::filterAdmin()
*/
protected static $adminTags = array('a', 'abbr', 'acronym', 'address', 'article', 'aside', 'b', 'bdi', 'bdo', 'big', 'blockquote', 'br', 'caption', 'cite', 'code', 'col', 'colgroup', 'command', 'dd', 'del', 'details', 'dfn', 'div', 'dl', 'dt', 'em', 'figcaption', 'figure', 'footer', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr', 'i', 'img', 'ins', 'kbd', 'li', 'mark', 'menu', 'meter', 'nav', 'ol', 'output', 'p', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'small', 'span', 'strong', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time', 'tr', 'tt', 'u', 'ul', 'var', 'wbr');
protected static $adminTags = ['a', 'abbr', 'acronym', 'address', 'article', 'aside', 'b', 'bdi', 'bdo', 'big', 'blockquote', 'br', 'caption', 'cite', 'code', 'col', 'colgroup', 'command', 'dd', 'del', 'details', 'dfn', 'div', 'dl', 'dt', 'em', 'figcaption', 'figure', 'footer', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr', 'i', 'img', 'ins', 'kbd', 'li', 'mark', 'menu', 'meter', 'nav', 'ol', 'output', 'p', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'small', 'span', 'strong', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time', 'tr', 'tt', 'u', 'ul', 'var', 'wbr'];
/**
* The default list of HTML tags allowed by filter().
@ -25,7 +25,7 @@ class Xss {
*
* @see \Drupal\Component\Utility\Xss::filter()
*/
protected static $htmlTags = array('a', 'em', 'strong', 'cite', 'blockquote', 'code', 'ul', 'ol', 'li', 'dl', 'dt', 'dd');
protected static $htmlTags = ['a', 'em', 'strong', 'cite', 'blockquote', 'code', 'ul', 'ol', 'li', 'dl', 'dt', 'dd'];
/**
* Filters HTML to prevent cross-site-scripting (XSS) vulnerabilities.
@ -196,7 +196,7 @@ class Xss {
* Cleaned up version of the HTML attributes.
*/
protected static function attributes($attributes) {
$attributes_array = array();
$attributes_array = [];
$mode = 0;
$attribute_name = '';
$skip = FALSE;
@ -221,12 +221,12 @@ class Xss {
// such attributes.
// @see \Drupal\Component\Utility\UrlHelper::filterBadProtocol()
// @see http://www.w3.org/TR/html4/index/attributes.html
$skip_protocol_filtering = substr($attribute_name, 0, 5) === 'data-' || in_array($attribute_name, array(
$skip_protocol_filtering = substr($attribute_name, 0, 5) === 'data-' || in_array($attribute_name, [
'title',
'alt',
'rel',
'property',
));
]);
$working = $mode = 1;
$attributes = preg_replace('/^[-a-zA-Z][-a-zA-Z0-9]*/', '', $attributes);

View file

@ -6,7 +6,7 @@
"license": "GPL-2.0+",
"require": {
"php": ">=5.5.9",
"paragonie/random_compat": "~1.0",
"paragonie/random_compat": "^1.0|^2.0",
"drupal/core-render": "~8.2"
},
"autoload": {