|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is a part of GraphQL project. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Alexandr Viniychuk <[email protected]> |
|
6
|
|
|
* created: 5/1/16 11:19 AM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Youshido\GraphQL\Type\Config\Traits; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Youshido\GraphQL\Type\AbstractType; |
|
13
|
|
|
use Youshido\GraphQL\Type\Config\Config; |
|
14
|
|
|
use Youshido\GraphQL\Type\Field\Field; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class ConfigCallTrait |
|
18
|
|
|
* @package Youshido\GraphQL\Type\Config\Traits |
|
19
|
|
|
* |
|
20
|
|
|
* @method string getDescription() |
|
21
|
|
|
* @method string getKind() |
|
22
|
|
|
* @method AbstractType getNamedType() |
|
23
|
|
|
* @method $this setType($type) |
|
24
|
|
|
* @method Field getField($field) |
|
25
|
|
|
* @method bool hasField($field) |
|
26
|
|
|
* @method bool hasFields() |
|
27
|
|
|
* @method bool isDeprecated() |
|
28
|
|
|
* @method string getDeprecationReason() |
|
29
|
|
|
* @property Config $config |
|
30
|
|
|
* |
|
31
|
|
|
*/ |
|
32
|
|
|
trait ConfigCallTrait |
|
33
|
|
|
{ |
|
34
|
21 |
|
public function __call($method, $arguments) |
|
35
|
|
|
{ |
|
36
|
21 |
|
$propertyName = false; |
|
37
|
21 |
|
$passAlongMethods = ['hasField', 'addField', 'addFields', 'removeField', 'getFields', 'hasFields', 'getField', 'getNamedType']; |
|
38
|
|
|
|
|
39
|
21 |
|
if (in_array($method, $passAlongMethods)) { |
|
40
|
19 |
|
$this->checkBuild(); |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
19 |
|
return call_user_func_array([$this->config, $method], $arguments); |
|
43
|
14 |
View Code Duplication |
} elseif (substr($method, 0, 3) == 'get') { |
|
|
|
|
|
|
44
|
12 |
|
$propertyName = lcfirst(substr($method, 3)); |
|
45
|
6 |
|
} elseif (substr($method, 0, 3) == 'set') { |
|
46
|
6 |
|
$propertyName = lcfirst(substr($method, 3)); |
|
47
|
6 |
|
$this->config->set($propertyName, $arguments[0]); |
|
48
|
|
|
|
|
49
|
6 |
|
return $this; |
|
50
|
|
|
} elseif (substr($method, 0, 2) == 'is') { |
|
51
|
|
|
$propertyName = lcfirst(substr($method, 2)); |
|
52
|
|
|
} |
|
53
|
12 |
|
if (in_array($propertyName, ['name', 'description', 'deprecationReason', 'isDeprecated', 'field', 'type'])) { |
|
54
|
12 |
|
return $this->config->get($propertyName); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
throw new \Exception('Call to undefined method ' . $method); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: