1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This software package is licensed under `AGPL, Commercial` license[s]. |
5
|
|
|
* |
6
|
|
|
* @package maslosoft/zamm |
7
|
|
|
* @license AGPL, Commercial |
8
|
|
|
* |
9
|
|
|
* @copyright Copyright (c) Peter Maselkowski <[email protected]> |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Maslosoft\Zamm; |
14
|
|
|
|
15
|
|
|
use Maslosoft\Zamm\Helpers\InlineWrapper; |
16
|
|
|
use Maslosoft\Zamm\Interfaces\SourceAccessorInterface; |
17
|
|
|
use Maslosoft\Zamm\Traits\SourceMagic; |
18
|
|
|
use ReflectionClass; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* This simply return names of methods and properties. |
22
|
|
|
* This is helper for IDE's. |
23
|
|
|
* Use this together with @var type hint. |
24
|
|
|
* |
25
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
26
|
|
|
*/ |
27
|
|
|
class Namer implements SourceAccessorInterface |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
use SourceMagic; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Working class name |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $className = ''; |
37
|
|
|
protected $info = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* |
41
|
|
|
* @var ApiUrl |
42
|
|
|
*/ |
43
|
|
|
protected $link = null; |
44
|
|
|
|
45
|
|
|
public function __construct($className = null) |
46
|
|
|
{ |
47
|
|
|
$this->className = $className; |
48
|
|
|
$this->info = new ReflectionClass($this->className); |
49
|
|
|
$this->link = new ApiUrl($className); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Set wrapper defaults |
54
|
|
|
* @return InlineWrapper |
55
|
|
|
*/ |
56
|
|
|
public static function defaults() |
57
|
|
|
{ |
58
|
|
|
return InlineWrapper::defaults(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function __get($name) |
62
|
|
|
{ |
63
|
|
|
// This is to get class name formatted, without invoking property() |
64
|
|
|
if ($name === 'md' || $name === 'html' || $name === 'short') |
65
|
|
|
{ |
66
|
|
|
if (!$this->info->hasProperty($name)) |
67
|
|
|
{ |
68
|
|
|
return (new InlineWrapper($this->_type(), (string) $this->link, $this->getTitle()))->$name; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
return $this->_get($name); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* |
76
|
|
|
* @param string $name |
77
|
|
|
* @return InlineWrapper |
78
|
|
|
*/ |
79
|
|
|
public function method($name) |
80
|
|
|
{ |
81
|
|
|
assert($this->info->hasMethod($name)); |
82
|
|
|
$link = $this->link->method($name); |
83
|
|
|
return new InlineWrapper($this->_method($name), $link, $this->getTitle("$name()")); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
protected function _method($name) |
87
|
|
|
{ |
88
|
|
|
return sprintf('%s::%s()', $this->className, $name); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* |
93
|
|
|
* @param string $name |
94
|
|
|
* @return InlineWrapper |
95
|
|
|
*/ |
96
|
|
|
public function property($name) |
97
|
|
|
{ |
98
|
|
|
assert($this->info->hasProperty($name)); |
99
|
|
|
$link = $this->link->property($name); |
100
|
|
|
return new InlineWrapper($this->_property($name), $link, $this->getTitle($name)); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
protected function _property($name) |
104
|
|
|
{ |
105
|
|
|
return sprintf('%s::%s', $this->className, $name); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public static function __callStatic($name, $arguments) |
109
|
|
|
{ |
110
|
|
|
return new InlineWrapper(sprintf('%s', $name)); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
protected function _type() |
114
|
|
|
{ |
115
|
|
|
return $this->className; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function __toString() |
119
|
|
|
{ |
120
|
|
|
$link = (string) $this->link; |
121
|
|
|
return (string) new InlineWrapper($this->_type(), $link, $this->getTitle()); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
private function getTitle($name = '') |
125
|
|
|
{ |
126
|
|
|
if (!empty($name)) |
127
|
|
|
{ |
128
|
|
|
return sprintf('%s::%s', $this->info->name, $name); |
129
|
|
|
} |
130
|
|
|
return $this->info->name; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
} |
134
|
|
|
|