Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / dependency-injection / Compiler / ResolveInvalidReferencesPass.php
index 85dbceb9a61ec526e290eb64f6dd4405485abb58..5b58fb1ecf74972931d3f974a5514b66710411c6 100644 (file)
@@ -71,16 +71,19 @@ class ResolveInvalidReferencesPass implements CompilerPassInterface
      *
      * @param array $arguments    An array of Reference objects
      * @param bool  $inMethodCall
+     * @param bool  $inCollection
      *
      * @return array
      *
      * @throws RuntimeException When the config is invalid
      */
-    private function processArguments(array $arguments, $inMethodCall = false)
+    private function processArguments(array $arguments, $inMethodCall = false, $inCollection = false)
     {
+        $isNumeric = array_keys($arguments) === range(0, count($arguments) - 1);
+
         foreach ($arguments as $k => $argument) {
             if (is_array($argument)) {
-                $arguments[$k] = $this->processArguments($argument, $inMethodCall);
+                $arguments[$k] = $this->processArguments($argument, $inMethodCall, true);
             } elseif ($argument instanceof Reference) {
                 $id = (string) $argument;
 
@@ -91,6 +94,10 @@ class ResolveInvalidReferencesPass implements CompilerPassInterface
                 if (!$exists && ContainerInterface::NULL_ON_INVALID_REFERENCE === $invalidBehavior) {
                     $arguments[$k] = null;
                 } elseif (!$exists && ContainerInterface::IGNORE_ON_INVALID_REFERENCE === $invalidBehavior) {
+                    if ($inCollection) {
+                        unset($arguments[$k]);
+                        continue;
+                    }
                     if ($inMethodCall) {
                         throw new RuntimeException('Method shouldn\'t be called.');
                     }
@@ -100,6 +107,11 @@ class ResolveInvalidReferencesPass implements CompilerPassInterface
             }
         }
 
+        // Ensure numerically indexed arguments have sequential numeric keys.
+        if ($isNumeric) {
+            $arguments = array_values($arguments);
+        }
+
         return $arguments;
     }
 }