Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / league / container / src / Inflector / InflectorAggregate.php
1 <?php
2
3 namespace League\Container\Inflector;
4
5 use League\Container\ImmutableContainerAwareTrait;
6
7 class InflectorAggregate implements InflectorAggregateInterface
8 {
9     use ImmutableContainerAwareTrait;
10
11     /**
12      * @var array
13      */
14     protected $inflectors = [];
15
16     /**
17      * {@inheritdoc}
18      */
19     public function add($type, callable $callback = null)
20     {
21         if (is_null($callback)) {
22             $inflector = new Inflector;
23             $this->inflectors[$type] = $inflector;
24
25             return $inflector;
26         }
27
28         $this->inflectors[$type] = $callback;
29     }
30
31     /**
32      * {@inheritdoc}
33      */
34     public function inflect($object)
35     {
36         foreach ($this->inflectors as $type => $inflector) {
37             if (! $object instanceof $type) {
38                 continue;
39             }
40
41             if ($inflector instanceof Inflector) {
42                 $inflector->setContainer($this->getContainer());
43                 $inflector->inflect($object);
44                 continue;
45             }
46
47             // must be dealing with a callable as the inflector
48             call_user_func_array($inflector, [$object]);
49         }
50
51         return $object;
52     }
53 }