Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Providers/GraphQLiteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
62 changes: 62 additions & 0 deletions src/SanePsr11ContainerAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php


namespace TheCodingMachine\GraphQLite\Laravel;


use function class_exists;
use Illuminate\Contracts\Container\Container;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

/**
* A container adapter around Laravel containers that adds a "sane" implementation of PSR-11.
* Notably, "has" will return true if the class exists, since Laravel is an auto-wiring framework.
*/
class SanePsr11ContainerAdapter implements ContainerInterface
{
/**
* @var Container
*/
private $container;

public function __construct(Container $container)
{
$this->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);
}
}