Skip to content

Commit 4dc38ce

Browse files
authored
Merge pull request #45 from moufmouf/cache_symfony5
Configuring cache for Symfony 5
2 parents 82ead38 + b81d6b8 commit 4dc38ce

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ matrix:
1515
include:
1616
# Test the latest stable release
1717
- php: 7.2
18+
env: PHPSTAN=true
1819
- php: 7.3
1920
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"
2021

@@ -51,7 +52,7 @@ script:
5152
# simple-phpunit is the PHPUnit wrapper provided by the PHPUnit Bridge component and
5253
# it helps with testing legacy code and deprecations (composer require symfony/phpunit-bridge)
5354
#- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS
54-
- composer phpstan
55+
- if [[ $PHPSTAN == true ]]; then composer phpstan; fi
5556
- ./vendor/bin/phpunit
5657

5758
after_script:

DependencyInjection/GraphqliteCompilerPass.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ public function process(ContainerBuilder $container)
250250
$this->mapAdderToTag('graphql.field_middleware', 'addFieldMiddleware', $container, $schemaFactory);
251251
$this->mapAdderToTag('graphql.type_mapper', 'addTypeMapper', $container, $schemaFactory);
252252
$this->mapAdderToTag('graphql.type_mapper_factory', 'addTypeMapperFactory', $container, $schemaFactory);
253+
254+
// Configure cache
255+
if (ApcuAdapter::isSupported()) {
256+
$container->setAlias('graphqlite.cache', 'graphqlite.apcucache');
257+
} else {
258+
$container->setAlias('graphqlite.cache', 'graphqlite.phpfilescache');
259+
}
253260
}
254261

255262
private function registerController(string $controllerClassName, ContainerBuilder $container): void

Resources/config/container/graphqlite.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<defaults autowire="true" autoconfigure="true" public="false" />
1414

1515
<service id="TheCodingMachine\GraphQLite\SchemaFactory">
16-
<argument index="1" type="service" id="service_container" />
16+
<argument type="service" id="graphqlite.psr16cache" />
17+
<argument type="service" id="service_container" />
1718
<call method="setAuthenticationService">
1819
<argument type="service" id="TheCodingMachine\GraphQLite\Security\AuthenticationServiceInterface" />
1920
</call>
@@ -102,5 +103,24 @@
102103
</argument>
103104
<tag name="graphql.type_mapper_factory"/>
104105
</service>
106+
107+
<service id="graphqlite.phpfilescache" class="Symfony\Component\Cache\Adapter\PhpFilesAdapter">
108+
<argument>graphqlite</argument>
109+
</service>
110+
111+
<service id="graphqlite.apcucache" class="Symfony\Component\Cache\Adapter\ApcuAdapter">
112+
<argument>graphqlite</argument>
113+
</service>
114+
115+
<service id="graphqlite.psr16cache" class="Symfony\Component\Cache\Psr16Cache">
116+
<argument type="service" id="graphqlite.cache" />
117+
</service>
118+
119+
<service id="graphqlite.cacheclearer" class="Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer">
120+
<argument type="collection">
121+
<argument/>
122+
</argument>
123+
<tag name="kernel.cache_clearer"/>
124+
</service>
105125
</services>
106126
</container>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"symfony/security-bundle": "^4.1.9 | ^5",
3535
"symfony/yaml": "^4.1.9 | ^5",
3636
"phpunit/phpunit": "^7.5.1",
37-
"phpstan/phpstan": "^0.10.6",
37+
"phpstan/phpstan-shim": "^0.11.19",
3838
"beberlei/porpaginas": "^1.2",
3939
"php-coveralls/php-coveralls": "^2.1.0"
4040
},

phpstan.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
parameters:
22
ignoreErrors:
33
- "#Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition::children\\(\\)#"
4-
# Error triggered by a bad PHPDoc in Symfony
5-
- '#Parameter \#4 $roles of class Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken constructor expects array<string>, array<string|Symfony\\Component\\Security\\Core\\Role\\Role> given.#'
6-
- '#Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) invoked with 2 parameters, 1 required.#'
7-
- '#Cannot cast object|string to string.#'
84
#includes:
95
# - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon

0 commit comments

Comments
 (0)