1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the ApiGen (http://apigen.org) |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view |
7
|
|
|
* the file LICENSE that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace ApiGen\Templating\Filters; |
11
|
|
|
|
12
|
|
|
abstract class Filters |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Calls public method with args if exists and passes args. |
17
|
|
|
* |
18
|
|
|
* @param string $name |
19
|
|
|
* @throws \Exception |
20
|
|
|
* @return mixed |
21
|
|
|
*/ |
22
|
|
|
public function loader($name) |
23
|
|
|
{ |
24
|
|
|
if (method_exists($this, $name)) { |
25
|
|
|
$args = array_slice(func_get_args(), 1); |
26
|
|
|
return call_user_func_array([$this, $name], $args); |
27
|
|
|
} |
28
|
|
|
return null; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param string $string |
34
|
|
|
* @return string |
35
|
|
|
*/ |
36
|
|
|
public static function urlize($string) |
37
|
|
|
{ |
38
|
|
|
return preg_replace('~[^\w]~', '.', $string); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $name |
44
|
|
|
* @param bool $trimNamespaceSeparator |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
protected function getTypeName($name, $trimNamespaceSeparator = true) |
48
|
|
|
{ |
49
|
|
|
$names = [ |
50
|
|
|
'int' => 'integer', |
51
|
|
|
'bool' => 'boolean', |
52
|
|
|
'double' => 'float', |
53
|
|
|
'void' => '', |
54
|
|
|
'FALSE' => 'false', |
55
|
|
|
'TRUE' => 'true', |
56
|
|
|
'NULL' => 'null', |
57
|
|
|
'callback' => 'callable' |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
// Simple type |
61
|
|
|
if (strlen($name) > 2 && substr($name, -2) === '[]') { |
62
|
|
|
$clearName = substr($name, 0, -2); |
63
|
|
|
if (isset($names[$clearName])) { |
64
|
|
|
return $names[$clearName] . '[]'; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
if (isset($names[$name])) { |
68
|
|
|
return $names[$name]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// Class, constant or function |
72
|
|
|
return $trimNamespaceSeparator ? ltrim($name, '\\') : $name; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param string $url |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
private function url($url) |
81
|
|
|
{ |
82
|
|
|
return rawurlencode($url); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|