1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* The MIT License |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 Transformer-. |
7
|
|
|
* |
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
10
|
|
|
* in the Software without restriction, including without limitation the rights |
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
13
|
|
|
* furnished to do so, subject to the following conditions: |
14
|
|
|
* |
15
|
|
|
* The above copyright notice and this permission notice shall be included in |
16
|
|
|
* all copies or substantial portions of the Software. |
17
|
|
|
* |
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
24
|
|
|
* THE SOFTWARE. |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace danielgp\informator; |
28
|
|
|
|
29
|
|
|
trait InformatorDynamicFunctions |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
protected function callDynamicFunctionToGetResults(array $inLabelsArray) |
33
|
|
|
{ |
34
|
|
|
switch (count($inLabelsArray)) { |
35
|
|
|
case 1: |
36
|
|
|
return call_user_func([$this, $inLabelsArray[0]]); |
37
|
|
|
break; |
|
|
|
|
38
|
|
|
case 2: |
39
|
|
|
if (is_array($inLabelsArray[1])) { |
40
|
|
|
return call_user_func_array([$this, $inLabelsArray[0]], [$inLabelsArray[1]]); |
41
|
|
|
} |
42
|
|
|
$dynFnPrmtr = $this->evaluateParameterAgainstKnownFunctions($inLabelsArray[1]); |
43
|
|
|
return call_user_func([$this, $inLabelsArray[0]], $dynFnPrmtr); |
44
|
|
|
break; |
|
|
|
|
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function evaluateParameterAgainstKnownFunctions($inParameter) |
49
|
|
|
{ |
50
|
|
|
$outParameter = $inParameter; |
51
|
|
|
$standardPhpFunctions = [ |
52
|
|
|
'get_loaded_extensions', |
53
|
|
|
'stream_get_filters', |
54
|
|
|
'stream_get_transports', |
55
|
|
|
'stream_get_wrappers', |
56
|
|
|
]; |
57
|
|
|
if (in_array($inParameter, $standardPhpFunctions)) { |
58
|
|
|
$outParameter = call_user_func($inParameter); |
59
|
|
|
} |
60
|
|
|
return $outParameter; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.