diff --git a/src/Providers/GraphQLiteServiceProvider.php b/src/Providers/GraphQLiteServiceProvider.php index 2680e23..6c5a95e 100644 --- a/src/Providers/GraphQLiteServiceProvider.php +++ b/src/Providers/GraphQLiteServiceProvider.php @@ -14,6 +14,7 @@ use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface; use TheCodingMachine\GraphQLite\Laravel\Controllers\GraphQLiteController; use TheCodingMachine\GraphQLite\Laravel\Middlewares\GraphQLMiddleware; +use TheCodingMachine\GraphQLite\Laravel\SanePsr11ContainerAdapter; use TheCodingMachine\GraphQLite\Schema; use TheCodingMachine\GraphQLite\SchemaFactory; use GraphQL\Type\Schema as WebonyxSchema; @@ -62,7 +63,7 @@ public function register() }); $this->app->singleton(SchemaFactory::class, function (Application $app) { - $service = new SchemaFactory($app->make(Repository::class), $app); + $service = new SchemaFactory($app->make(Repository::class), new SanePsr11ContainerAdapter($app)); $controllers = config('graphqlite.controllers', 'App\\Http\\Controllers'); if (!is_iterable($controllers)) { diff --git a/src/SanePsr11ContainerAdapter.php b/src/SanePsr11ContainerAdapter.php new file mode 100644 index 0000000..fd4fd75 --- /dev/null +++ b/src/SanePsr11ContainerAdapter.php @@ -0,0 +1,62 @@ +container = $container; + } + + /** + * Finds an entry of the container by its identifier and returns it. + * + * @param string $id Identifier of the entry to look for. + * + * @throws NotFoundExceptionInterface No entry was found for **this** identifier. + * @throws ContainerExceptionInterface Error while retrieving the entry. + * + * @return mixed Entry. + */ + public function get($id) + { + return $this->container->get($id); + } + + /** + * Returns true if the container can return an entry for the given identifier. + * Returns false otherwise. + * + * `has($id)` returning true does not mean that `get($id)` will not throw an exception. + * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. + * + * @param string $id Identifier of the entry to look for. + * + * @return bool + */ + public function has($id) + { + if (class_exists($id)) { + return true; + } + return $this->container->has($id); + } +} \ No newline at end of file