| @@ 10-120 (lines=111) @@ | ||
| 7 | use Drupal\Core\Extension\ModuleHandlerInterface; |
|
| 8 | use Drupal\Core\Plugin\DefaultPluginManager; |
|
| 9 | ||
| 10 | class FieldPluginManager extends DefaultPluginManager { |
|
| 11 | ||
| 12 | /** |
|
| 13 | * Static cache of plugin instances. |
|
| 14 | * |
|
| 15 | * @var \Drupal\graphql\Plugin\FieldPluginInterface[] |
|
| 16 | */ |
|
| 17 | protected $instances; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * FieldPluginManager constructor. |
|
| 21 | * |
|
| 22 | * @param bool|string $pluginSubdirectory |
|
| 23 | * The plugin's subdirectory. |
|
| 24 | * @param \Traversable $namespaces |
|
| 25 | * An object that implements \Traversable which contains the root paths |
|
| 26 | * keyed by the corresponding namespace to look for plugin implementations. |
|
| 27 | * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler |
|
| 28 | * The module handler. |
|
| 29 | * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend |
|
| 30 | * The cache backend. |
|
| 31 | * @param string|null $pluginInterface |
|
| 32 | * The interface each plugin should implement. |
|
| 33 | * @param string $pluginAnnotationName |
|
| 34 | * The name of the annotation that contains the plugin definition. |
|
| 35 | * @param array $config |
|
| 36 | * The configuration service parameter. |
|
| 37 | */ |
|
| 38 | public function __construct( |
|
| 39 | $pluginSubdirectory, |
|
| 40 | \Traversable $namespaces, |
|
| 41 | ModuleHandlerInterface $moduleHandler, |
|
| 42 | CacheBackendInterface $cacheBackend, |
|
| 43 | $pluginInterface, |
|
| 44 | $pluginAnnotationName, |
|
| 45 | array $config |
|
| 46 | ) { |
|
| 47 | parent::__construct( |
|
| 48 | $pluginSubdirectory, |
|
| 49 | $namespaces, |
|
| 50 | $moduleHandler, |
|
| 51 | $pluginInterface, |
|
| 52 | $pluginAnnotationName |
|
| 53 | ); |
|
| 54 | ||
| 55 | $this->alterInfo('graphql_fields'); |
|
| 56 | $this->useCaches(empty($config['development'])); |
|
| 57 | $this->setCacheBackend($cacheBackend, 'fields', ['graphql']); |
|
| 58 | } |
|
| 59 | ||
| 60 | /** |
|
| 61 | * {@inheritdoc} |
|
| 62 | */ |
|
| 63 | public function getInstance(array $options) { |
|
| 64 | if (!isset($this->instances[$options['id']])) { |
|
| 65 | $this->instances[$options['id']] = $this->createInstance($options['id']); |
|
| 66 | } |
|
| 67 | ||
| 68 | return $this->instances[$options['id']]; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * {@inheritdoc} |
|
| 73 | */ |
|
| 74 | public function clearCachedDefinitions() { |
|
| 75 | parent::clearCachedDefinitions(); |
|
| 76 | $this->instances = []; |
|
| 77 | } |
|
| 78 | ||
| 79 | /** |
|
| 80 | * {@inheritdoc} |
|
| 81 | */ |
|
| 82 | protected function setCachedDefinitions($definitions) { |
|
| 83 | $this->definitions = $definitions; |
|
| 84 | $this->cacheSet($this->cacheKey, $definitions, $this->getCacheMaxAge(), $this->getCacheTags()); |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * {@inheritdoc} |
|
| 89 | */ |
|
| 90 | public function getCacheTags() { |
|
| 91 | $definitions = $this->getDefinitions(); |
|
| 92 | return array_reduce($definitions, function ($carry, $current) { |
|
| 93 | if (!empty($current['schema_cache_tags'])) { |
|
| 94 | return Cache::mergeTags($carry, $current['schema_cache_tags']); |
|
| 95 | } |
|
| 96 | ||
| 97 | return $carry; |
|
| 98 | }, $this->cacheTags); |
|
| 99 | } |
|
| 100 | ||
| 101 | /** |
|
| 102 | * {@inheritdoc} |
|
| 103 | */ |
|
| 104 | public function getCacheMaxAge() { |
|
| 105 | $definitions = $this->getDefinitions(); |
|
| 106 | $age = Cache::PERMANENT; |
|
| 107 | foreach ($definitions as $definition) { |
|
| 108 | if (!isset($definition['schema_cache_max_age'])) { |
|
| 109 | continue; |
|
| 110 | } |
|
| 111 | ||
| 112 | // Bail out early if the cache max age is 0. |
|
| 113 | if (($age = Cache::mergeMaxAges($age, $definition['schema_cache_max_age'])) === 0) { |
|
| 114 | return $age; |
|
| 115 | } |
|
| 116 | } |
|
| 117 | ||
| 118 | return $age; |
|
| 119 | } |
|
| 120 | } |
|
| 121 | ||
| @@ 10-120 (lines=111) @@ | ||
| 7 | use Drupal\Core\Extension\ModuleHandlerInterface; |
|
| 8 | use Drupal\Core\Plugin\DefaultPluginManager; |
|
| 9 | ||
| 10 | class MutationPluginManager extends DefaultPluginManager { |
|
| 11 | ||
| 12 | /** |
|
| 13 | * Static cache of plugin instances. |
|
| 14 | * |
|
| 15 | * @var \Drupal\graphql\Plugin\MutationPluginInterface[] |
|
| 16 | */ |
|
| 17 | protected $instances; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * FieldPluginManager constructor. |
|
| 21 | * |
|
| 22 | * @param bool|string $pluginSubdirectory |
|
| 23 | * The plugin's subdirectory. |
|
| 24 | * @param \Traversable $namespaces |
|
| 25 | * An object that implements \Traversable which contains the root paths |
|
| 26 | * keyed by the corresponding namespace to look for plugin implementations. |
|
| 27 | * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler |
|
| 28 | * The module handler. |
|
| 29 | * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend |
|
| 30 | * The cache backend. |
|
| 31 | * @param string|null $pluginInterface |
|
| 32 | * The interface each plugin should implement. |
|
| 33 | * @param string $pluginAnnotationName |
|
| 34 | * The name of the annotation that contains the plugin definition. |
|
| 35 | * @param array $config |
|
| 36 | * The configuration service parameter. |
|
| 37 | */ |
|
| 38 | public function __construct( |
|
| 39 | $pluginSubdirectory, |
|
| 40 | \Traversable $namespaces, |
|
| 41 | ModuleHandlerInterface $moduleHandler, |
|
| 42 | CacheBackendInterface $cacheBackend, |
|
| 43 | $pluginInterface, |
|
| 44 | $pluginAnnotationName, |
|
| 45 | array $config |
|
| 46 | ) { |
|
| 47 | parent::__construct( |
|
| 48 | $pluginSubdirectory, |
|
| 49 | $namespaces, |
|
| 50 | $moduleHandler, |
|
| 51 | $pluginInterface, |
|
| 52 | $pluginAnnotationName |
|
| 53 | ); |
|
| 54 | ||
| 55 | $this->alterInfo('graphql_mutations'); |
|
| 56 | $this->useCaches(empty($config['development'])); |
|
| 57 | $this->setCacheBackend($cacheBackend, 'mutations', ['graphql']); |
|
| 58 | } |
|
| 59 | ||
| 60 | /** |
|
| 61 | * {@inheritdoc} |
|
| 62 | */ |
|
| 63 | public function getInstance(array $options) { |
|
| 64 | if (!isset($this->instances[$options['id']])) { |
|
| 65 | $this->instances[$options['id']] = $this->createInstance($options['id']); |
|
| 66 | } |
|
| 67 | ||
| 68 | return $this->instances[$options['id']]; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * {@inheritdoc} |
|
| 73 | */ |
|
| 74 | public function clearCachedDefinitions() { |
|
| 75 | parent::clearCachedDefinitions(); |
|
| 76 | $this->instances = []; |
|
| 77 | } |
|
| 78 | ||
| 79 | /** |
|
| 80 | * {@inheritdoc} |
|
| 81 | */ |
|
| 82 | protected function setCachedDefinitions($definitions) { |
|
| 83 | $this->definitions = $definitions; |
|
| 84 | $this->cacheSet($this->cacheKey, $definitions, $this->getCacheMaxAge(), $this->getCacheTags()); |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * {@inheritdoc} |
|
| 89 | */ |
|
| 90 | public function getCacheTags() { |
|
| 91 | $definitions = $this->getDefinitions(); |
|
| 92 | return array_reduce($definitions, function ($carry, $current) { |
|
| 93 | if (!empty($current['schema_cache_tags'])) { |
|
| 94 | return Cache::mergeTags($carry, $current['schema_cache_tags']); |
|
| 95 | } |
|
| 96 | ||
| 97 | return $carry; |
|
| 98 | }, $this->cacheTags); |
|
| 99 | } |
|
| 100 | ||
| 101 | /** |
|
| 102 | * {@inheritdoc} |
|
| 103 | */ |
|
| 104 | public function getCacheMaxAge() { |
|
| 105 | $definitions = $this->getDefinitions(); |
|
| 106 | $age = Cache::PERMANENT; |
|
| 107 | foreach ($definitions as $definition) { |
|
| 108 | if (!isset($definition['schema_cache_max_age'])) { |
|
| 109 | continue; |
|
| 110 | } |
|
| 111 | ||
| 112 | // Bail out early if the cache max age is 0. |
|
| 113 | if (($age = Cache::mergeMaxAges($age, $definition['schema_cache_max_age'])) === 0) { |
|
| 114 | return $age; |
|
| 115 | } |
|
| 116 | } |
|
| 117 | ||
| 118 | return $age; |
|
| 119 | } |
|
| 120 | } |
|
| 121 | ||
| @@ 10-123 (lines=114) @@ | ||
| 7 | use Drupal\Core\Extension\ModuleHandlerInterface; |
|
| 8 | use Drupal\Core\Plugin\DefaultPluginManager; |
|
| 9 | ||
| 10 | class TypePluginManager extends DefaultPluginManager implements TypePluginManagerInterface { |
|
| 11 | ||
| 12 | /** |
|
| 13 | * Static cache of plugin instances. |
|
| 14 | * |
|
| 15 | * @var \Drupal\graphql\Plugin\TypePluginInterface[] |
|
| 16 | */ |
|
| 17 | protected $instances; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * TypePluginManager constructor. |
|
| 21 | * |
|
| 22 | * @param bool|string $pluginSubdirectory |
|
| 23 | * The plugin's subdirectory. |
|
| 24 | * @param \Traversable $namespaces |
|
| 25 | * An object that implements \Traversable which contains the root paths |
|
| 26 | * keyed by the corresponding namespace to look for plugin implementations. |
|
| 27 | * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler |
|
| 28 | * The module handler. |
|
| 29 | * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend |
|
| 30 | * The cache backend. |
|
| 31 | * @param string|null $pluginInterface |
|
| 32 | * The interface each plugin should implement. |
|
| 33 | * @param string $pluginAnnotationName |
|
| 34 | * The name of the annotation that contains the plugin definition. |
|
| 35 | * @param string $pluginType |
|
| 36 | * The plugin type. |
|
| 37 | * @param array $config |
|
| 38 | * The configuration service parameter. |
|
| 39 | */ |
|
| 40 | public function __construct( |
|
| 41 | $pluginSubdirectory, |
|
| 42 | \Traversable $namespaces, |
|
| 43 | ModuleHandlerInterface $moduleHandler, |
|
| 44 | CacheBackendInterface $cacheBackend, |
|
| 45 | $pluginInterface, |
|
| 46 | $pluginAnnotationName, |
|
| 47 | $pluginType, |
|
| 48 | array $config |
|
| 49 | ) { |
|
| 50 | parent::__construct( |
|
| 51 | $pluginSubdirectory, |
|
| 52 | $namespaces, |
|
| 53 | $moduleHandler, |
|
| 54 | $pluginInterface, |
|
| 55 | $pluginAnnotationName |
|
| 56 | ); |
|
| 57 | ||
| 58 | $this->alterInfo("graphql_{$pluginType}"); |
|
| 59 | $this->useCaches(empty($config['development'])); |
|
| 60 | $this->setCacheBackend($cacheBackend, $pluginType, ['graphql']); |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * {@inheritdoc} |
|
| 65 | */ |
|
| 66 | public function getInstance(array $options) { |
|
| 67 | if (!isset($this->instances[$options['id']])) { |
|
| 68 | $this->instances[$options['id']] = $this->createInstance($options['id']); |
|
| 69 | } |
|
| 70 | ||
| 71 | return $this->instances[$options['id']]; |
|
| 72 | } |
|
| 73 | ||
| 74 | /** |
|
| 75 | * {@inheritdoc} |
|
| 76 | */ |
|
| 77 | public function clearCachedDefinitions() { |
|
| 78 | parent::clearCachedDefinitions(); |
|
| 79 | $this->instances = []; |
|
| 80 | } |
|
| 81 | ||
| 82 | /** |
|
| 83 | * {@inheritdoc} |
|
| 84 | */ |
|
| 85 | protected function setCachedDefinitions($definitions) { |
|
| 86 | $this->definitions = $definitions; |
|
| 87 | $this->cacheSet($this->cacheKey, $definitions, $this->getCacheMaxAge(), $this->getCacheTags()); |
|
| 88 | } |
|
| 89 | ||
| 90 | /** |
|
| 91 | * {@inheritdoc} |
|
| 92 | */ |
|
| 93 | public function getCacheTags() { |
|
| 94 | $definitions = $this->getDefinitions(); |
|
| 95 | return array_reduce($definitions, function ($carry, $current) { |
|
| 96 | if (!empty($current['schema_cache_tags'])) { |
|
| 97 | return Cache::mergeTags($carry, $current['schema_cache_tags']); |
|
| 98 | } |
|
| 99 | ||
| 100 | return $carry; |
|
| 101 | }, $this->cacheTags); |
|
| 102 | } |
|
| 103 | ||
| 104 | /** |
|
| 105 | * {@inheritdoc} |
|
| 106 | */ |
|
| 107 | public function getCacheMaxAge() { |
|
| 108 | $definitions = $this->getDefinitions(); |
|
| 109 | $age = Cache::PERMANENT; |
|
| 110 | foreach ($definitions as $definition) { |
|
| 111 | if (!isset($definition['schema_cache_max_age'])) { |
|
| 112 | continue; |
|
| 113 | } |
|
| 114 | ||
| 115 | // Bail out early if the cache max age is 0. |
|
| 116 | if (($age = Cache::mergeMaxAges($age, $definition['schema_cache_max_age'])) === 0) { |
|
| 117 | return $age; |
|
| 118 | } |
|
| 119 | } |
|
| 120 | ||
| 121 | return $age; |
|
| 122 | } |
|
| 123 | } |
|
| 124 | ||
| @@ 10-120 (lines=111) @@ | ||
| 7 | use Drupal\Core\Extension\ModuleHandlerInterface; |
|
| 8 | use Drupal\Core\Plugin\DefaultPluginManager; |
|
| 9 | ||
| 10 | class SubscriptionPluginManager extends DefaultPluginManager { |
|
| 11 | ||
| 12 | /** |
|
| 13 | * Static cache of plugin instances. |
|
| 14 | * |
|
| 15 | * @var \Drupal\graphql\Plugin\SubscriptionPluginInterface[] |
|
| 16 | */ |
|
| 17 | protected $instances; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * FieldPluginManager constructor. |
|
| 21 | * |
|
| 22 | * @param bool|string $pluginSubdirectory |
|
| 23 | * The plugin's subdirectory. |
|
| 24 | * @param \Traversable $namespaces |
|
| 25 | * An object that implements \Traversable which contains the root paths |
|
| 26 | * keyed by the corresponding namespace to look for plugin implementations. |
|
| 27 | * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler |
|
| 28 | * The module handler. |
|
| 29 | * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend |
|
| 30 | * The cache backend. |
|
| 31 | * @param string|null $pluginInterface |
|
| 32 | * The interface each plugin should implement. |
|
| 33 | * @param string $pluginAnnotationName |
|
| 34 | * The name of the annotation that contains the plugin definition. |
|
| 35 | * @param array $config |
|
| 36 | * The configuration service parameter. |
|
| 37 | */ |
|
| 38 | public function __construct( |
|
| 39 | $pluginSubdirectory, |
|
| 40 | \Traversable $namespaces, |
|
| 41 | ModuleHandlerInterface $moduleHandler, |
|
| 42 | CacheBackendInterface $cacheBackend, |
|
| 43 | $pluginInterface, |
|
| 44 | $pluginAnnotationName, |
|
| 45 | array $config |
|
| 46 | ) { |
|
| 47 | parent::__construct( |
|
| 48 | $pluginSubdirectory, |
|
| 49 | $namespaces, |
|
| 50 | $moduleHandler, |
|
| 51 | $pluginInterface, |
|
| 52 | $pluginAnnotationName |
|
| 53 | ); |
|
| 54 | ||
| 55 | $this->alterInfo('graphql_subscriptions'); |
|
| 56 | $this->useCaches(empty($config['development'])); |
|
| 57 | $this->setCacheBackend($cacheBackend, 'subscriptions', ['graphql']); |
|
| 58 | } |
|
| 59 | ||
| 60 | /** |
|
| 61 | * {@inheritdoc} |
|
| 62 | */ |
|
| 63 | public function getInstance(array $options) { |
|
| 64 | if (!isset($this->instances[$options['id']])) { |
|
| 65 | $this->instances[$options['id']] = $this->createInstance($options['id']); |
|
| 66 | } |
|
| 67 | ||
| 68 | return $this->instances[$options['id']]; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * {@inheritdoc} |
|
| 73 | */ |
|
| 74 | public function clearCachedDefinitions() { |
|
| 75 | parent::clearCachedDefinitions(); |
|
| 76 | $this->instances = []; |
|
| 77 | } |
|
| 78 | ||
| 79 | /** |
|
| 80 | * {@inheritdoc} |
|
| 81 | */ |
|
| 82 | protected function setCachedDefinitions($definitions) { |
|
| 83 | $this->definitions = $definitions; |
|
| 84 | $this->cacheSet($this->cacheKey, $definitions, $this->getCacheMaxAge(), $this->getCacheTags()); |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * {@inheritdoc} |
|
| 89 | */ |
|
| 90 | public function getCacheTags() { |
|
| 91 | $definitions = $this->getDefinitions(); |
|
| 92 | return array_reduce($definitions, function ($carry, $current) { |
|
| 93 | if (!empty($current['schema_cache_tags'])) { |
|
| 94 | return Cache::mergeTags($carry, $current['schema_cache_tags']); |
|
| 95 | } |
|
| 96 | ||
| 97 | return $carry; |
|
| 98 | }, $this->cacheTags); |
|
| 99 | } |
|
| 100 | ||
| 101 | /** |
|
| 102 | * {@inheritdoc} |
|
| 103 | */ |
|
| 104 | public function getCacheMaxAge() { |
|
| 105 | $definitions = $this->getDefinitions(); |
|
| 106 | $age = Cache::PERMANENT; |
|
| 107 | foreach ($definitions as $definition) { |
|
| 108 | if (!isset($definition['schema_cache_max_age'])) { |
|
| 109 | continue; |
|
| 110 | } |
|
| 111 | ||
| 112 | // Bail out early if the cache max age is 0. |
|
| 113 | if (($age = Cache::mergeMaxAges($age, $definition['schema_cache_max_age'])) === 0) { |
|
| 114 | return $age; |
|
| 115 | } |
|
| 116 | } |
|
| 117 | ||
| 118 | return $age; |
|
| 119 | } |
|
| 120 | } |
|
| 121 | ||