|
1
|
|
|
<?php |
|
2
|
|
|
/******************************************************************************* |
|
3
|
|
|
* This file is part of the GraphQL Bundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) YnloUltratech <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
******************************************************************************/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Ynlo\GraphQLBundle\Definition\Extension; |
|
12
|
|
|
|
|
13
|
|
|
use Ynlo\GraphQLBundle\Component\TaggedServices\TaggedServices; |
|
14
|
|
|
use Ynlo\GraphQLBundle\Component\TaggedServices\TagSpecification; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* ExtensionManager |
|
18
|
|
|
*/ |
|
19
|
|
View Code Duplication |
class DefinitionExtensionManager |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var DefinitionExtensionInterface[] |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $extensions; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var bool |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $loaded = false; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var TaggedServices |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $taggedServices; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* ExtensionManager constructor. |
|
38
|
|
|
* |
|
39
|
|
|
* @param TaggedServices $taggedServices |
|
40
|
|
|
*/ |
|
41
|
21 |
|
public function __construct(TaggedServices $taggedServices) |
|
42
|
|
|
{ |
|
43
|
21 |
|
$this->taggedServices = $taggedServices; |
|
44
|
21 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return array|DefinitionExtensionInterface[] |
|
48
|
|
|
*/ |
|
49
|
1 |
|
public function getExtensions() |
|
50
|
|
|
{ |
|
51
|
1 |
|
if ($this->loaded) { |
|
52
|
|
|
return $this->extensions; |
|
53
|
|
|
|
|
54
|
|
|
} |
|
55
|
1 |
|
$this->extensions = []; |
|
56
|
|
|
|
|
57
|
|
|
/** @var TagSpecification $extensions */ |
|
58
|
1 |
|
$taggedServices = $this->taggedServices->findTaggedServices('graphql.definition_extension'); |
|
59
|
1 |
|
foreach ($taggedServices as $tagSpecification) { |
|
60
|
|
|
/** @var DefinitionExtensionInterface $extension */ |
|
61
|
1 |
|
$extension = $tagSpecification->getService(); |
|
62
|
1 |
|
$this->extensions[$extension->getName()] = $extension; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
$this->loaded = true; |
|
66
|
|
|
|
|
67
|
1 |
|
return $this->extensions; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.