*/ public readonly array $cycle; /** * Create a new exception instance. * * @param array $cycle The seeders forming the dependency cycle */ public function __construct(array $cycle) { $this->cycle = $cycle; $cycleStr = implode(' -> ', $cycle); parent::__construct( "Circular dependency detected in seeders: {$cycleStr}" ); } /** * Create an exception from a dependency path. * * @param array $path The path of seeders leading to the cycle * @param string $duplicate The seeder that was found again, completing the cycle */ public static function fromPath(array $path, string $duplicate): self { // Find where the cycle starts $cycleStart = array_search($duplicate, $path, true); $cycle = array_slice($path, $cycleStart); $cycle[] = $duplicate; return new self($cycle); } }