From 5ca4636c0ae80c0ddbcf97760963dc03b8e8cb0a Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 31 May 2018 08:24:40 +0200 Subject: [PATCH] Fix compile cache warmup on init cache --- .travis.yml | 2 -- CacheWarmer/CompileCacheWarmer.php | 6 ++++ DependencyInjection/Configuration.php | 2 +- Generator/TypeGenerator.php | 35 ++++++++++++++++--- Resources/config/services.yml | 1 + Tests/Functional/App/config/access/config.yml | 1 - Tests/Functional/App/config/config.yml | 21 +++++++++++ Tests/Functional/App/config/public/config.yml | 1 - .../App/config/queryComplexityEnv/config.yml | 2 +- .../App/config/queryMaxDepthEnv/config.yml | 2 +- Tests/Functional/App/config/security.yml | 19 ---------- 11 files changed, 61 insertions(+), 31 deletions(-) delete mode 100644 Tests/Functional/App/config/security.yml diff --git a/.travis.yml b/.travis.yml index 0de2a4d6a..acc61dd2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,8 +34,6 @@ matrix: - php: nightly env: COMPOSER_UPDATE_FLAGS=--ignore-platform-reqs allow_failures: - - php: 7.2 - env: SYMFONY_VERSION=4.1.* DEPENDENCIES=dev - php: nightly env: COMPOSER_UPDATE_FLAGS=--ignore-platform-reqs diff --git a/CacheWarmer/CompileCacheWarmer.php b/CacheWarmer/CompileCacheWarmer.php index 87935a530..bf0cd9e12 100644 --- a/CacheWarmer/CompileCacheWarmer.php +++ b/CacheWarmer/CompileCacheWarmer.php @@ -28,6 +28,12 @@ public function isOptional() */ public function warmUp($cacheDir) { + // use warm up cache dir if type generator cache dir not already explicitly declare + $baseCacheDir = $this->typeGenerator->getBaseCacheDir(); + if (null === $this->typeGenerator->getCacheDir(false)) { + $this->typeGenerator->setBaseCacheDir($cacheDir); + } $this->typeGenerator->compile(TypeGenerator::MODE_WRITE | TypeGenerator::MODE_OVERRIDE); + $this->typeGenerator->setBaseCacheDir($baseCacheDir); } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 6c7856425..1dd8c3515 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -46,7 +46,7 @@ public function getConfigTreeBuilder() ->scalarNode('internal_error_message')->defaultNull()->end() ->variableNode('default_resolver')->defaultValue([Resolver::class, 'defaultResolveFn'])->end() ->scalarNode('class_namespace')->defaultValue('Overblog\\GraphQLBundle\\__DEFINITIONS__')->end() - ->scalarNode('cache_dir')->defaultValue($this->cacheDir.'/overblog/graphql-bundle/__definitions__')->end() + ->scalarNode('cache_dir')->defaultNull()->end() ->booleanNode('use_classloader_listener')->defaultTrue()->end() ->booleanNode('auto_compile')->defaultTrue()->end() ->booleanNode('show_debug_info')->defaultFalse()->end() diff --git a/Generator/TypeGenerator.php b/Generator/TypeGenerator.php index 00686d974..1f53ce2a0 100644 --- a/Generator/TypeGenerator.php +++ b/Generator/TypeGenerator.php @@ -22,27 +22,52 @@ class TypeGenerator extends BaseTypeGenerator private $useClassMap = true; + private $baseCacheDir; + private static $classMapLoaded = false; - public function __construct($classNamespace, array $skeletonDirs, $cacheDir, callable $defaultResolver, array $configs, $useClassMap = true) + public function __construct($classNamespace, array $skeletonDirs, $cacheDir, callable $defaultResolver, array $configs, $useClassMap = true, $baseCacheDir = null) { $this->setCacheDir($cacheDir); $this->defaultResolver = $defaultResolver; $this->configs = $this->processConfigs($configs); $this->useClassMap = $useClassMap; + $this->baseCacheDir = $baseCacheDir; + parent::__construct($classNamespace, $skeletonDirs); } /** - * @return string + * @return string|null + */ + public function getBaseCacheDir() + { + return $this->baseCacheDir; + } + + /** + * @param string|null $baseCacheDir */ - public function getCacheDir() + public function setBaseCacheDir($baseCacheDir) { - return $this->cacheDir; + $this->baseCacheDir = $baseCacheDir; + } + + /** + * @return string|null + */ + public function getCacheDir(/*bool $useDefault = true*/) + { + $useDefault = func_num_args() > 0 ? func_get_arg(0) : true; + if ($useDefault) { + return $this->cacheDir ?: $this->baseCacheDir.'/overblog/graphql-bundle/__definitions__'; + } else { + return $this->cacheDir; + } } /** - * @param string $cacheDir + * @param string|null $cacheDir * * @return $this */ diff --git a/Resources/config/services.yml b/Resources/config/services.yml index ae70602a8..17ad9ec0c 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -98,6 +98,7 @@ services: - "%overblog_graphql.default_resolver%" - "%overblog_graphql_types.config%" - "%overblog_graphql.use_classloader_listener%" + - "%kernel.cache_dir%" calls: - ["addUseStatement", ["Symfony\\Component\\DependencyInjection\\ContainerInterface"]] - ["addUseStatement", ["Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface"]] diff --git a/Tests/Functional/App/config/access/config.yml b/Tests/Functional/App/config/access/config.yml index b9158fe75..bc6af7294 100644 --- a/Tests/Functional/App/config/access/config.yml +++ b/Tests/Functional/App/config/access/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config.yml } - - { resource: ../security.yml } - { resource: ../connection/services.yml } - { resource: ../mutation/services.yml } diff --git a/Tests/Functional/App/config/config.yml b/Tests/Functional/App/config/config.yml index d3d1ad89a..9dcbe22bf 100644 --- a/Tests/Functional/App/config/config.yml +++ b/Tests/Functional/App/config/config.yml @@ -8,6 +8,27 @@ framework: profiler: enabled: false +security: + providers: + in_memory: + memory: + users: + ryan: + password: 123 + roles: 'ROLE_USER' + admin: + password: 123 + roles: 'ROLE_ADMIN' + encoders: + Symfony\Component\Security\Core\User\User: plaintext + firewalls: + graph: + pattern: ^/ + http_basic: ~ + stateless: true + anonymous: true + + overblog_graphql: definitions: config_validation: true diff --git a/Tests/Functional/App/config/public/config.yml b/Tests/Functional/App/config/public/config.yml index 901ce6e7d..d6147da5f 100644 --- a/Tests/Functional/App/config/public/config.yml +++ b/Tests/Functional/App/config/public/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config.yml } - - { resource: ../security.yml } overblog_graphql: definitions: diff --git a/Tests/Functional/App/config/queryComplexityEnv/config.yml b/Tests/Functional/App/config/queryComplexityEnv/config.yml index e2eb1d756..4ffdeac06 100644 --- a/Tests/Functional/App/config/queryComplexityEnv/config.yml +++ b/Tests/Functional/App/config/queryComplexityEnv/config.yml @@ -3,7 +3,7 @@ imports: - { resource: ../connection/services.yml } parameters: - env(GRAPHQL_QUERY_MAX_COMPLEXITY): 10 + env(GRAPHQL_QUERY_MAX_COMPLEXITY): "10" overblog_graphql: security: diff --git a/Tests/Functional/App/config/queryMaxDepthEnv/config.yml b/Tests/Functional/App/config/queryMaxDepthEnv/config.yml index ae134d970..029f93458 100644 --- a/Tests/Functional/App/config/queryMaxDepthEnv/config.yml +++ b/Tests/Functional/App/config/queryMaxDepthEnv/config.yml @@ -3,7 +3,7 @@ imports: - { resource: ../connection/services.yml } parameters: - env(GRAPHQL_QUERY_MAX_DEPTH): 3 + env(GRAPHQL_QUERY_MAX_DEPTH): "3" overblog_graphql: security: diff --git a/Tests/Functional/App/config/security.yml b/Tests/Functional/App/config/security.yml deleted file mode 100644 index 37325245c..000000000 --- a/Tests/Functional/App/config/security.yml +++ /dev/null @@ -1,19 +0,0 @@ -security: - providers: - in_memory: - memory: - users: - ryan: - password: 123 - roles: 'ROLE_USER' - admin: - password: 123 - roles: 'ROLE_ADMIN' - encoders: - Symfony\Component\Security\Core\User\User: plaintext - firewalls: - graph: - pattern: ^/ - http_basic: ~ - stateless: true - anonymous: true