Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / league / container / src / Inflector / InflectorAggregate.php
diff --git a/vendor/league/container/src/Inflector/InflectorAggregate.php b/vendor/league/container/src/Inflector/InflectorAggregate.php
new file mode 100644 (file)
index 0000000..f855233
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+namespace League\Container\Inflector;
+
+use League\Container\ImmutableContainerAwareTrait;
+
+class InflectorAggregate implements InflectorAggregateInterface
+{
+    use ImmutableContainerAwareTrait;
+
+    /**
+     * @var array
+     */
+    protected $inflectors = [];
+
+    /**
+     * {@inheritdoc}
+     */
+    public function add($type, callable $callback = null)
+    {
+        if (is_null($callback)) {
+            $inflector = new Inflector;
+            $this->inflectors[$type] = $inflector;
+
+            return $inflector;
+        }
+
+        $this->inflectors[$type] = $callback;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function inflect($object)
+    {
+        foreach ($this->inflectors as $type => $inflector) {
+            if (! $object instanceof $type) {
+                continue;
+            }
+
+            if ($inflector instanceof Inflector) {
+                $inflector->setContainer($this->getContainer());
+                $inflector->inflect($object);
+                continue;
+            }
+
+            // must be dealing with a callable as the inflector
+            call_user_func_array($inflector, [$object]);
+        }
+
+        return $object;
+    }
+}