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\Annotation\Plugin; |
12
|
|
|
|
13
|
|
|
use Doctrine\Common\Util\Inflector; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Can use this annotation as base to se plugin options. |
17
|
|
|
* Override and define all plugin settings. |
18
|
|
|
*/ |
19
|
|
|
abstract class PluginConfigAnnotation |
20
|
|
|
{ |
21
|
6 |
|
public function __construct(array $config = []) |
22
|
|
|
{ |
23
|
|
|
//if only one value is given, the first property is set with the given value |
24
|
6 |
|
if (isset($config['value']) && count($config) === 1) { |
25
|
6 |
|
$ref = new \ReflectionClass(get_class($this)); |
26
|
6 |
|
if ($ref->getProperties()) { |
27
|
6 |
|
$propName = $ref->getProperties()[0]->getName(); |
28
|
6 |
|
$this->$propName = $config['value']; |
29
|
6 |
|
$this->config[Inflector::tableize($propName)] = $config['value']; |
|
|
|
|
30
|
|
|
} |
31
|
|
|
} else { |
32
|
3 |
|
foreach ($config as $key => $value) { |
33
|
|
|
//dynamically added to avoid ide auto-complete for this property |
34
|
3 |
|
$this->config[Inflector::tableize($key)] = $value; |
35
|
|
|
} |
36
|
|
|
} |
37
|
6 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Must return the array with plugin config |
41
|
|
|
* |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
1 |
|
public function getConfig(): array |
45
|
|
|
{ |
46
|
1 |
|
return $this->config ?? []; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Must return the plugin name to apply this config |
51
|
|
|
* |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
1 |
|
public function getName(): string |
55
|
|
|
{ |
56
|
1 |
|
preg_match('/\w+$/', get_class($this), $matches); |
57
|
|
|
|
58
|
1 |
|
return Inflector::tableize($matches[0]); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|