*/ class ExtractTopLevelItemsFilter { /** @var string */ private $topLevelItemName; /** @var string */ private $delimiter; /** * Extract Top Level Item constructor. * * @param string $topLevelItemName * @param string $delimiter */ public function __construct(string $topLevelItemName, string $delimiter = '') { $this->topLevelItemName = $topLevelItemName; $this->delimiter = $delimiter; } /** * Remove top-level item and elevate its children to the top level * * @param ConfigValues $values * @return ConfigValues */ public function __invoke(ConfigValues $values): ConfigValues { $items = $values->getArrayCopy(); $delimiterParts = $this->delimiter ? array_filter(explode($this->delimiter, $this->topLevelItemName)) : [$this->topLevelItemName]; while ($current = array_shift($delimiterParts)) { $items = $this->elevate($items, $current); } return new ConfigValues($items); } /** * @param array $items * @param string $key * @return array */ private function elevate(array $items, string $key): array { if (! isset($items[$key]) or ! is_array($items[$key])) { return $items; } // Elevate all of the sub-items from the array that are children of the prefix to remove foreach ($items[$key] as $k => $v) { // If item already exists in root node, throw exception if (isset($items[$k])) { throw new ConfigLoaderException( sprintf( 'Name collision (%s) when removing %s.%s from config values', $k, $this->topLevelItemName, $k ) ); } $items[$k] = $v; } unset($items[$key]); return $items; } } __halt_compiler();----SIGNATURE:----G1HR2UkJLjdRVGFLZYZqIl7AroErs4mdKasoFVFwCNHvA5Lwho3QMUYf5MArRLnZLGd6R+ppOUzZ68ksSRkhlglv2k4mCB6mYS+LmRL4MfyHAMeOYS/FEftE+VjLbEO+Q3FjkaUDGAtuiqWB6CFSRYRfXOGfXpLtpRogBs4qv7wPCudDSD/idMCEco49kI2qDB/BQECBgJbbuL6kJTeC7o1S1O1eBDpfWBXgX8Lcjz/5c8mU42tTTyVN8hx7pbtkEGW7eWk6BR3rRA4tixO+pkUvJ5e44aV/TFnT7BFLqxZ28DVUa61mqSQjeVWa3ucetAQeRnhoEZS6xAbDRj4lL38D1EyHS30s7Rqto8i2s2r9IdDIL92W4JySgQmQNW8FTkn5OLyWtbumOParpYcvEXL4Zc25eAvhYvaI5QvqxUCwJ4bhyKKQLJp19ES5r6oveYMpWe5mM/6UNu0wGT2I07Q1VH3vUs88vA5gDpBDtBU5H0Gw+m1xx2QTrTDPLawA47s1cECrpBDspM7iDtpbsrynnGuXDSxFCKFu1Dxem9X7cirGasJpORlL0njX3pu+Gj9Rz0dS5B47jTddzcr1/qbnGyP2xHGFKPUo4pR9b9n7peOF7JD+Z/QD1Gm0PyIdS0DUsbvVXaAudhROs6EqTcjCA3vZeuu6f0hEmjwYg74=----ATTACHMENT:----NTE3OTg3MzkyNzQ3OTI1MiA2NDkwNDMwNjg2NzU2Mjc5IDIzMTQ5NjEzODU3NzY3OTE=