-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathCallRerouting.php
More file actions
110 lines (100 loc) · 4.02 KB
/
CallRerouting.php
File metadata and controls
110 lines (100 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* @author Ignas Rudaitis <ignas.rudaitis@gmail.com>
* @link http://patchwork2.org/
* @copyright 2010-2018 Ignas Rudaitis
* @license http://www.opensource.org/licenses/mit-license.html
*/
namespace Patchwork\CodeManipulation\Actions\CallRerouting;
use Patchwork\CodeManipulation\Actions\Generic;
use Patchwork\CallRerouting;
use Patchwork\Utils;
const CALL_INTERCEPTION_CODE = '
$__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}";
$__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : "";
if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) {
$__pwCalledClass = $__pwClass ? \get_called_class() : null;
$__pwFrame = \count(\debug_backtrace(0));
$__pwRefs = %s;
$__pwRefOffset = 0;
if (\Patchwork\CallRerouting\dispatch(
$__pwClass,
$__pwCalledClass,
__FUNCTION__,
$__pwFrame,
$__pwResult,
\array_merge(\array_slice($__pwRefs, $__pwRefOffset, \func_num_args()), \array_slice(\func_get_args(), \count($__pwRefs)))
)) {
return $__pwResult;
}
}
unset($__pwClass, $__pwCalledClass, $__pwResult, $__pwClosureName, $__pwFrame, $__pwRefs, $__pwRefOffset);
';
const CALL_INTERCEPTION_CODE_VOID_TYPED = '
$__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}";
$__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : "";
if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) {
$__pwCalledClass = $__pwClass ? \get_called_class() : null;
$__pwFrame = \count(\debug_backtrace(0));
$__pwRefs = %s;
$__pwRefOffset = 0;
if (\Patchwork\CallRerouting\dispatch(
$__pwClass,
$__pwCalledClass,
__FUNCTION__,
$__pwFrame,
$__pwResult,
\array_merge(\array_slice($__pwRefs, $__pwRefOffset, \func_num_args()), \array_slice(\func_get_args(), \count($__pwRefs)))
)) {
if ($__pwResult !== null) {
throw new \Patchwork\Exceptions\NonNullToVoid;
}
return;
}
}
unset($__pwClass, $__pwCalledClass, $__pwResult, $__pwClosureName, $__pwFrame, $__pwRefOffset);
';
const CALL_INTERCEPTION_CODE_NEVER_TYPED = '
$__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}";
$__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : "";
if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) {
$__pwCalledClass = $__pwClass ? \get_called_class() : null;
$__pwFrame = \count(\debug_backtrace(0));
$__pwRefs = %s;
$__pwRefOffset = 0;
if (\Patchwork\CallRerouting\dispatch(
$__pwClass,
$__pwCalledClass,
__FUNCTION__,
$__pwFrame,
$__pwResult,
\array_merge(\array_slice($__pwRefs, $__pwRefOffset, \func_num_args()), \array_slice(\func_get_args(), \count($__pwRefs)))
)) {
throw new \Patchwork\Exceptions\ReturnFromNever;
}
}
unset($__pwClass, $__pwCalledClass, $__pwResult, $__pwClosureName, $__pwFrame, $__pwRefOffset);
';
const QUEUE_DEPLOYMENT_CODE = '\Patchwork\CallRerouting\deployQueue()';
function markPreprocessedFiles()
{
return Generic\markPreprocessedFiles(CallRerouting\State::$preprocessedFiles);
}
function injectCallInterceptionCode()
{
return Generic\prependCodeToFunctions(
Utils\condense(CALL_INTERCEPTION_CODE),
array(
'void' => Utils\condense(CALL_INTERCEPTION_CODE_VOID_TYPED),
'never' => Utils\condense(CALL_INTERCEPTION_CODE_NEVER_TYPED),
),
true
);
}
function injectQueueDeploymentCode()
{
return Generic\chain(array(
Generic\injectFalseExpressionAtBeginnings(QUEUE_DEPLOYMENT_CODE),
Generic\injectCodeAfterClassDefinitions(QUEUE_DEPLOYMENT_CODE . ';'),
));
}