Dingo\Api\Console\Command\Docs::addControllerIfNotExists PHP Method

addControllerIfNotExists() protected method

Add a controller to the collection if it does not exist. If the controller implements an interface suffixed with "Docs" it will be used instead of the controller.
protected addControllerIfNotExists ( Collection $controllers, object $controller ) : void
$controllers Illuminate\Support\Collection
$controller object
return void
    protected function addControllerIfNotExists(Collection $controllers, $controller)
    {
        $class = get_class($controller);
        if ($controllers->has($class)) {
            return;
        }
        $reflection = new ReflectionClass($controller);
        $interface = Arr::first($reflection->getInterfaces(), function ($key, $value) {
            return ends_with($key, 'Docs');
        });
        if ($interface) {
            $controller = $interface;
        }
        $controllers->put($class, $controller);
    }