public function getSorted($names) { $all = $this->whereIn('name', $names)->sortBy('priority')->replaceProcessors(); $all->each(function ($processor) use($all) { /** @var Processor $annotation */ $annotation = $processor['annotation']; foreach ($annotation->before as $before) { $otherProcessor = $all->where('name', $before)->first(); if ($otherProcessor !== null && false === in_array($annotation->name, $otherProcessor['after'], true)) { $otherProcessor['after'][] = $annotation->name; $all->set($before, $otherProcessor); } } }); $sorter = new Sorter(); foreach ($all as $item) { $sorter->addItem($item['name'], $item['after']); } $sorted = $sorter->sort(); if (count($sorter->getMissing()) > 0) { if (static::$handleMissing === self::MISSING_IGNORED) { } elseif (static::$handleMissing === self::MISSING_THROWS_EXECEPTION) { $dep = array_keys($sorter->getMissing()); $dep = implode(', ', $dep); throw CodexException::because("Sorter encountered a missing dependency for {$dep}"); } } $sorted = array_merge($sorted, array_diff($names, $sorted)); return $sorted; }