Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Upgrade league/container (#289)
Browse files Browse the repository at this point in the history
* Upgrade league/container to current version

* Update service providers to use the new share method
  • Loading branch information
crisu83 authored Oct 2, 2018
1 parent a25fe4e commit d044ba6
Show file tree
Hide file tree
Showing 11 changed files with 596 additions and 584 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"require": {
"php": ">=7.1",
"ext-mbstring": "*",
"league/container": "^2.4",
"league/container": "^3.2",
"react/promise": "^2.5"
},
"require-dev": {
Expand Down
4 changes: 2 additions & 2 deletions src/Execution/ExecutionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExecutionProvider extends AbstractServiceProvider
*/
public function register()
{
$this->container->add(ExecutionInterface::class, Execution::class, true/* $shared */);
$this->container->add(ValuesHelper::class, ValuesHelper::class, true/* $shared */);
$this->container->share(ExecutionInterface::class, Execution::class);
$this->container->share(ValuesHelper::class, ValuesHelper::class);
}
}
10 changes: 4 additions & 6 deletions src/GraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use Digia\GraphQL\Validation\ValidationProvider;
use Digia\GraphQL\Validation\ValidatorInterface;
use League\Container\Container;
use League\Container\ContainerInterface;

class GraphQL
{
Expand Down Expand Up @@ -110,14 +109,13 @@ public static function getInstance(): self

/**
* @param string $id
* @param array $args
* @return mixed
*/
public static function make(string $id, array $args = [])
public static function make(string $id)
{
return static::getInstance()
->getContainer()
->get($id, $args);
->get($id);
}

/**
Expand Down Expand Up @@ -282,9 +280,9 @@ public function getContainer(): Container
/**
* Registers the service provides with the container.
*
* @param ContainerInterface $container
* @param Container $container
*/
protected function registerProviders(ContainerInterface $container): void
protected function registerProviders(Container $container): void
{
foreach (self::$providers as $className) {
$container->addServiceProvider($className);
Expand Down
6 changes: 2 additions & 4 deletions src/Language/LanguageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ class LanguageProvider extends AbstractServiceProvider
*/
public function register()
{
$this->container->add(NodeBuilderInterface::class, NodeBuilder::class, true/* $shared */);

$this->container->share(NodeBuilderInterface::class, NodeBuilder::class);
$this->container->share(NodePrinterInterface::class, NodePrinter::class);
$this->container->add(ParserInterface::class, Parser::class);

$this->container->add(NodePrinterInterface::class, NodePrinter::class, true/* $shared */);
}
}
2 changes: 1 addition & 1 deletion src/Schema/Validation/SchemaValidationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SchemaValidationProvider extends AbstractServiceProvider
*/
public function register()
{
$this->container->add(SchemaValidatorInterface::class, SchemaValidator::class, true);
$this->container->share(SchemaValidatorInterface::class, SchemaValidator::class);

// Rules
$this->container->add(RootTypesRule::class, RootTypesRule::class);
Expand Down
8 changes: 4 additions & 4 deletions src/Type/CoercerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class CoercerProvider extends AbstractServiceProvider
*/
public function register()
{
$this->container->add(BooleanCoercer::class, BooleanCoercer::class, true/* $shared */);
$this->container->add(FloatCoercer::class, FloatCoercer::class, true/* $shared */);
$this->container->add(IntCoercer::class, IntCoercer::class, true/* $shared */);
$this->container->add(StringCoercer::class, StringCoercer::class, true/* $shared */);
$this->container->share(BooleanCoercer::class, BooleanCoercer::class);
$this->container->share(FloatCoercer::class, FloatCoercer::class);
$this->container->share(IntCoercer::class, IntCoercer::class);
$this->container->share(StringCoercer::class, StringCoercer::class);
}
}
117 changes: 58 additions & 59 deletions src/Type/DirectivesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
use Digia\GraphQL\GraphQL;
use Digia\GraphQL\Language\DirectiveLocationEnum;
use League\Container\ServiceProvider\AbstractServiceProvider;
use function Digia\GraphQL\Type\booleanType;
use function Digia\GraphQL\Type\newDirective;
use function Digia\GraphQL\Type\newNonNull;
use function Digia\GraphQL\Type\stringType;

class DirectivesProvider extends AbstractServiceProvider
{
Expand All @@ -26,65 +22,68 @@ class DirectivesProvider extends AbstractServiceProvider
*/
public function register()
{
$this->container->add(GraphQL::INCLUDE_DIRECTIVE, function () {
return newDirective([
'name' => 'include',
'description' =>
'Directs the executor to include this field or fragment only when ' .
'the `if` argument is true.',
'locations' => [
DirectiveLocationEnum::FIELD,
DirectiveLocationEnum::FRAGMENT_SPREAD,
DirectiveLocationEnum::INLINE_FRAGMENT,
],
'args' => [
'if' => [
'type' => newNonNull(booleanType()),
'description' => 'Included when true.',
$this->container
->share(GraphQL::INCLUDE_DIRECTIVE, function () {
return newDirective([
'name' => 'include',
'description' =>
'Directs the executor to include this field or fragment only when ' .
'the `if` argument is true.',
'locations' => [
DirectiveLocationEnum::FIELD,
DirectiveLocationEnum::FRAGMENT_SPREAD,
DirectiveLocationEnum::INLINE_FRAGMENT,
],
],
]);
}, true/* $shared */);
'args' => [
'if' => [
'type' => newNonNull(booleanType()),
'description' => 'Included when true.',
],
],
]);
});

$this->container->add(GraphQL::SKIP_DIRECTIVE, function () {
return newDirective([
'name' => 'skip',
'description' =>
'Directs the executor to skip this field or fragment when the `if` ' .
'argument is true.',
'locations' => [
DirectiveLocationEnum::FIELD,
DirectiveLocationEnum::FRAGMENT_SPREAD,
DirectiveLocationEnum::INLINE_FRAGMENT,
],
'args' => [
'if' => [
'type' => newNonNull(booleanType()),
'description' => 'Skipped when true.',
$this->container
->share(GraphQL::SKIP_DIRECTIVE, function () {
return newDirective([
'name' => 'skip',
'description' =>
'Directs the executor to skip this field or fragment when the `if` ' .
'argument is true.',
'locations' => [
DirectiveLocationEnum::FIELD,
DirectiveLocationEnum::FRAGMENT_SPREAD,
DirectiveLocationEnum::INLINE_FRAGMENT,
],
'args' => [
'if' => [
'type' => newNonNull(booleanType()),
'description' => 'Skipped when true.',
],
],
],
]);
}, true/* $shared */);
]);
});

$this->container->add(GraphQL::DEPRECATED_DIRECTIVE, function () {
return newDirective([
'name' => 'deprecated',
'description' => 'Marks an element of a GraphQL schema as no longer supported.',
'locations' => [
DirectiveLocationEnum::FIELD_DEFINITION,
DirectiveLocationEnum::ENUM_VALUE,
],
'args' => [
'reason' => [
'type' => stringType(),
'description' =>
'Explains why this element was deprecated, usually also including a ' .
'suggestion for how to access supported similar data. Formatted ' .
'in [Markdown](https://daringfireball.net/projects/markdown/).',
'defaultValue' => DEFAULT_DEPRECATION_REASON,
$this->container
->share(GraphQL::DEPRECATED_DIRECTIVE, function () {
return newDirective([
'name' => 'deprecated',
'description' => 'Marks an element of a GraphQL schema as no longer supported.',
'locations' => [
DirectiveLocationEnum::FIELD_DEFINITION,
DirectiveLocationEnum::ENUM_VALUE,
],
]
]);
}, true/* $shared */);
'args' => [
'reason' => [
'type' => stringType(),
'description' =>
'Explains why this element was deprecated, usually also including a ' .
'suggestion for how to access supported similar data. Formatted ' .
'in [Markdown](https://daringfireball.net/projects/markdown/).',
'defaultValue' => DEFAULT_DEPRECATION_REASON,
],
]
]);
});
}
}
Loading

0 comments on commit d044ba6

Please sign in to comment.