From 4c60859864b97ce3ec6bb952dbedbe791d461108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 14 Feb 2019 18:22:08 +0100 Subject: [PATCH] Adding a PSR-11 container adapter to get back sane defaults --- src/Providers/GraphQLiteServiceProvider.php | 3 +- src/SanePsr11ContainerAdapter.php | 62 +++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/SanePsr11ContainerAdapter.php 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