Laravel version update
Laravel version update
This commit is contained in:
@@ -38,19 +38,17 @@ final class Context
|
||||
/**
|
||||
* Adds a value to the context.
|
||||
*
|
||||
* @param array|object $value The value to add.
|
||||
* @return int|string The ID of the stored value, either as
|
||||
* a string or integer.
|
||||
* @throws InvalidArgumentException Thrown if $value is not an array or
|
||||
* object
|
||||
* @param array|object $value The value to add.
|
||||
*
|
||||
* @return int|string The ID of the stored value, either as a string or integer.
|
||||
*
|
||||
* @throws InvalidArgumentException Thrown if $value is not an array or object
|
||||
*/
|
||||
public function add(&$value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return $this->addArray($value);
|
||||
}
|
||||
|
||||
else if (is_object($value)) {
|
||||
} elseif (is_object($value)) {
|
||||
return $this->addObject($value);
|
||||
}
|
||||
|
||||
@@ -62,20 +60,17 @@ final class Context
|
||||
/**
|
||||
* Checks if the given value exists within the context.
|
||||
*
|
||||
* @param array|object $value The value to check.
|
||||
* @return int|string|false The string or integer ID of the stored
|
||||
* value if it has already been seen, or
|
||||
* false if the value is not stored.
|
||||
* @throws InvalidArgumentException Thrown if $value is not an array or
|
||||
* object
|
||||
* @param array|object $value The value to check.
|
||||
*
|
||||
* @return int|string|false The string or integer ID of the stored value if it has already been seen, or false if the value is not stored.
|
||||
*
|
||||
* @throws InvalidArgumentException Thrown if $value is not an array or object
|
||||
*/
|
||||
public function contains(&$value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return $this->containsArray($value);
|
||||
}
|
||||
|
||||
else if (is_object($value)) {
|
||||
} elseif (is_object($value)) {
|
||||
return $this->containsObject($value);
|
||||
}
|
||||
|
||||
@@ -85,7 +80,8 @@ final class Context
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
private function addArray(array &$array)
|
||||
@@ -96,13 +92,32 @@ final class Context
|
||||
return $key;
|
||||
}
|
||||
|
||||
$key = count($this->arrays);
|
||||
$this->arrays[] = &$array;
|
||||
|
||||
return count($this->arrays) - 1;
|
||||
if (!isset($array[PHP_INT_MAX]) && !isset($array[PHP_INT_MAX - 1])) {
|
||||
$array[] = $key;
|
||||
$array[] = $this->objects;
|
||||
} else { /* cover the improbable case too */
|
||||
do {
|
||||
$key = random_int(PHP_INT_MIN, PHP_INT_MAX);
|
||||
} while (isset($array[$key]));
|
||||
|
||||
$array[$key] = $key;
|
||||
|
||||
do {
|
||||
$key = random_int(PHP_INT_MIN, PHP_INT_MAX);
|
||||
} while (isset($array[$key]));
|
||||
|
||||
$array[$key] = $this->objects;
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $object
|
||||
* @param object $object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function addObject($object)
|
||||
@@ -115,31 +130,20 @@ final class Context
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
private function containsArray(array &$array)
|
||||
{
|
||||
$keys = array_keys($this->arrays, $array, true);
|
||||
$hash = '_Key_' . microtime(true);
|
||||
$end = array_slice($array, -2);
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$this->arrays[$key][$hash] = $hash;
|
||||
|
||||
if (isset($array[$hash]) && $array[$hash] === $hash) {
|
||||
unset($this->arrays[$key][$hash]);
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
unset($this->arrays[$key][$hash]);
|
||||
}
|
||||
|
||||
return false;
|
||||
return isset($end[1]) && $end[1] === $this->objects ? $end[0] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $value
|
||||
* @param object $value
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
private function containsObject($value)
|
||||
@@ -150,4 +154,14 @@ final class Context
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
foreach ($this->arrays as &$array) {
|
||||
if (is_array($array)) {
|
||||
array_pop($array);
|
||||
array_pop($array);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user