*/ public function for(Type $type): array { // Merging the files bound to settings and the files bound to the type $files = [ ...array_map( fn (callable $callable) => (new ReflectionFunction(Closure::fromCallable($callable)))->getFileName(), $this->settings->callables(), ), ...$this->filesToWatch($type), ]; // Removing the duplicates $files = array_unique($files); // Filtering the empty/invalid file names $files = array_filter($files, fn ($value) => is_string($value)); /** @var list */ return array_values($files); } /** * @param array $files * @return array */ private function filesToWatch(Type $type, array $files = []): array { if (isset($files[$type->toString()])) { // Prevents infinite loop in case of circular references return []; } foreach (TypeHelper::traverseRecursively($type) as $subType) { $files = [...$files, ...$this->filesToWatch($subType, $files)]; } if ($type instanceof ObjectType) { $fileName = Reflection::class($type->className())->getFileName(); if (! $fileName) { return []; } $files[$type->toString()] = $fileName; $class = $this->classDefinitionRepository->for($type); foreach ($class->properties as $property) { $files = [...$files, ...$this->filesToWatch($property->type, $files)]; } } return $files; } }