We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 26 | class OverblogGraphQLExtension extends Extension implements PrependExtensionInterface |
||
| 27 | { |
||
| 28 | 15 | public function load(array $configs, ContainerBuilder $container) |
|
| 29 | { |
||
| 30 | 15 | $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
| 31 | 15 | $loader->load('services.yml'); |
|
| 32 | 15 | $loader->load('graphql_types.yml'); |
|
| 33 | |||
| 34 | 15 | $config = $this->treatConfigs($configs, $container); |
|
| 35 | |||
| 36 | 15 | $this->setExpressionLanguageDefaultParser($container); |
|
| 37 | 15 | $this->setServicesAliases($config, $container); |
|
|
|
|||
| 38 | 15 | $this->setSchemaBuilderArguments($config, $container); |
|
| 39 | 15 | $this->setSchemaArguments($config, $container); |
|
| 40 | 15 | $this->setErrorHandlerArguments($config, $container); |
|
| 41 | 15 | $this->setGraphiQLTemplate($config, $container); |
|
| 42 | 15 | $this->setSecurity($config, $container); |
|
| 43 | 15 | $this->setConfigBuilders($config); |
|
| 44 | 15 | $this->setVersions($config, $container); |
|
| 45 | 15 | $this->setShowDebug($config, $container); |
|
| 46 | 15 | $this->setAutoMappingParameters($config, $container); |
|
| 47 | |||
| 48 | 15 | $container->setParameter($this->getAlias().'.resources_dir', realpath(__DIR__.'/../Resources')); |
|
| 49 | 15 | } |
|
| 50 | |||
| 51 | 13 | public function prepend(ContainerBuilder $container) |
|
| 52 | { |
||
| 53 | 13 | $configs = $container->getExtensionConfig($this->getAlias()); |
|
| 54 | 13 | $configs = $container->getParameterBag()->resolveValue($configs); |
|
| 55 | 13 | $config = $this->treatConfigs($configs, $container, true); |
|
| 56 | |||
| 57 | /** @var OverblogGraphQLTypesExtension $typesExtension */ |
||
| 58 | 13 | $typesExtension = $container->getExtension($this->getAlias().'_types'); |
|
| 59 | 13 | $typesExtension->containerPrependExtensionConfig($config, $container); |
|
| 60 | 13 | } |
|
| 61 | |||
| 62 | 15 | private function setAutoMappingParameters(array $config, ContainerBuilder $container) |
|
| 63 | { |
||
| 64 | 15 | $container->setParameter($this->getAlias().'.auto_mapping.enabled', $config['definitions']['auto_mapping']['enabled']); |
|
| 65 | 15 | $container->setParameter($this->getAlias().'.auto_mapping.directories', $config['definitions']['auto_mapping']['directories']); |
|
| 66 | 15 | } |
|
| 67 | |||
| 68 | 15 | private function setExpressionLanguageDefaultParser(ContainerBuilder $container) |
|
| 69 | { |
||
| 70 | 15 | $class = version_compare(Kernel::VERSION, '3.2.0', '>=') ? |
|
| 71 | 15 | 'Symfony\\Component\\Cache\Adapter\\ArrayAdapter' |
|
| 72 | : 'Symfony\\Component\\ExpressionLanguage\\ParserCache\\ArrayParserCache' |
||
| 73 | 15 | ; |
|
| 74 | 15 | $definition = new Definition($class); |
|
| 75 | 15 | $definition->setPublic(false); |
|
| 76 | 15 | $container->setDefinition($this->getAlias().'.cache_expression_language_parser.default', $definition); |
|
| 77 | 15 | } |
|
| 78 | |||
| 79 | 15 | private function setShowDebug(array $config, ContainerBuilder $container) |
|
| 80 | { |
||
| 81 | 15 | $container->getDefinition($this->getAlias().'.request_executor')->replaceArgument(4, $config['definitions']['show_debug_info']); |
|
| 82 | 15 | } |
|
| 83 | |||
| 84 | 15 | private function setVersions(array $config, ContainerBuilder $container) |
|
| 85 | { |
||
| 86 | 15 | $container->setParameter($this->getAlias().'.versions.graphiql', $config['versions']['graphiql']); |
|
| 87 | 15 | $container->setParameter($this->getAlias().'.versions.react', $config['versions']['react']); |
|
| 88 | 15 | $container->setParameter($this->getAlias().'.versions.fetch', $config['versions']['fetch']); |
|
| 89 | 15 | } |
|
| 90 | |||
| 91 | 15 | private function setConfigBuilders(array $config) |
|
| 92 | { |
||
| 93 | 15 | foreach (['args', 'field'] as $category) { |
|
| 94 | 15 | if (!empty($config['definitions']['builders'][$category])) { |
|
| 95 | 1 | $method = 'add'.ucfirst($category).'BuilderClass'; |
|
| 96 | |||
| 97 | 1 | foreach ($config['definitions']['builders'][$category] as $params) { |
|
| 98 | 1 | TypeWithOutputFieldsDefinition::$method($params['alias'], $params['class']); |
|
| 99 | 1 | } |
|
| 100 | 1 | } |
|
| 101 | 15 | } |
|
| 102 | 15 | } |
|
| 103 | |||
| 104 | 15 | private function treatConfigs(array $configs, ContainerBuilder $container, $forceReload = false) |
|
| 105 | { |
||
| 106 | 15 | static $config = null; |
|
| 107 | |||
| 108 | 15 | if ($forceReload || null === $config) { |
|
| 109 | 15 | $configuration = $this->getConfiguration($configs, $container); |
|
| 110 | 15 | $config = $this->processConfiguration($configuration, $configs); |
|
| 111 | 15 | } |
|
| 112 | |||
| 113 | 15 | return $config; |
|
| 114 | } |
||
| 115 | |||
| 116 | 15 | private function setSecurity(array $config, ContainerBuilder $container) |
|
| 117 | { |
||
| 118 | 15 | $container->setParameter($this->getAlias().'.query_max_depth', $config['security']['query_max_depth']); |
|
| 119 | 15 | $container->setParameter($this->getAlias().'.query_max_complexity', $config['security']['query_max_complexity']); |
|
| 120 | 15 | } |
|
| 121 | |||
| 122 | 15 | private function setGraphiQLTemplate(array $config, ContainerBuilder $container) |
|
| 126 | |||
| 127 | 15 | private function setErrorHandlerArguments(array $config, ContainerBuilder $container) |
|
| 128 | { |
||
| 129 | 15 | $errorHandlerDefinition = $container->getDefinition($this->getAlias().'.error_handler'); |
|
| 130 | |||
| 131 | 15 | if (isset($config['definitions']['internal_error_message'])) { |
|
| 132 | 1 | $errorHandlerDefinition->replaceArgument(0, $config['definitions']['internal_error_message']); |
|
| 133 | 1 | } |
|
| 134 | |||
| 135 | 15 | if (isset($config['definitions']['exceptions'])) { |
|
| 136 | $errorHandlerDefinition |
||
| 137 | 15 | ->replaceArgument(2, $this->buildExceptionMap($config['definitions']['exceptions'])) |
|
| 138 | 15 | ->addMethodCall('setUserWarningClass', [$config['definitions']['exceptions']['types']['warnings']]) |
|
| 139 | 15 | ->addMethodCall('setUserErrorClass', [$config['definitions']['exceptions']['types']['errors']]) |
|
| 140 | ; |
||
| 141 | 15 | } |
|
| 142 | 15 | } |
|
| 143 | |||
| 144 | 15 | private function setSchemaBuilderArguments(array $config, ContainerBuilder $container) |
|
| 145 | { |
||
| 146 | 15 | $container->getDefinition($this->getAlias().'.schema_builder') |
|
| 147 | 15 | ->replaceArgument(1, $config['definitions']['config_validation']); |
|
| 148 | 15 | } |
|
| 149 | |||
| 150 | 15 | private function setSchemaArguments(array $config, ContainerBuilder $container) |
|
| 167 | |||
| 168 | 15 | private function setServicesAliases(array $config, ContainerBuilder $container) |
|
| 169 | { |
||
| 170 | 15 | if (isset($config['services'])) { |
|
| 171 | 15 | foreach ($config['services'] as $name => $id) { |
|
| 172 | 15 | $alias = sprintf('%s.%s', $this->getAlias(), $name); |
|
| 173 | 15 | $container->setAlias($alias, $id); |
|
| 174 | // set autowiring types for promise adapter service |
||
| 175 | 15 | if ($this->getAlias().'.promise_adapter' === $alias) { |
|
| 176 | 15 | $container->findDefinition($id)->setAutowiringTypes([PromiseAdapter::class]); |
|
| 177 | 15 | } |
|
| 178 | 15 | } |
|
| 179 | 15 | } |
|
| 180 | 15 | } |
|
| 181 | |||
| 182 | 15 | public function getAlias() |
|
| 183 | { |
||
| 184 | 15 | return 'overblog_graphql'; |
|
| 185 | } |
||
| 186 | |||
| 187 | 15 | public function getConfiguration(array $config, ContainerBuilder $container) |
|
| 191 | |||
| 192 | /** |
||
| 193 | * Returns a list of custom exceptions mapped to error/warning classes. |
||
| 194 | * |
||
| 195 | * @param array $exceptionConfig |
||
| 196 | * |
||
| 197 | * @return array Custom exception map, [exception => UserError/UserWarning] |
||
| 198 | */ |
||
| 199 | 15 | private function buildExceptionMap(array $exceptionConfig) |
|
| 200 | { |
||
| 201 | 15 | $exceptionMap = []; |
|
| 202 | 15 | $typeMap = $exceptionConfig['types']; |
|
| 203 | |||
| 204 | 15 | foreach ($exceptionConfig as $type => $exceptionList) { |
|
| 216 | } |
||
| 217 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.