From 4cb038dd5a4a963dfaac943c47289ba155edc259 Mon Sep 17 00:00:00 2001 From: Nick Bartkowiak Date: Tue, 25 Dec 2012 14:25:23 -0600 Subject: [PATCH] Added a way to change the depth of the getCallingFunction so child classes that override methods or have 'hops' can specifically define the depth to which the getCallingFunction will check to make sure we return the correct calling function. --- Machine/MachineAbstract.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Machine/MachineAbstract.php b/Machine/MachineAbstract.php index 02bf90c..63662c5 100644 --- a/Machine/MachineAbstract.php +++ b/Machine/MachineAbstract.php @@ -132,14 +132,19 @@ protected function makeCall($url) * some of our polymorphic requests as the calling function can tell us what * type of item is being requested. * + * @param integer $depth Depth defaults to 2 because 0 is this function and + * 1 will be the function that asked for the calling function. This can be + * changed by the calling function in case a specific calling function needs + * to be identified. This can be handy if the original calling function goes + * through a number of hops on its way to identification. + * * @return string The name of the function that called the function that * issued the getCallingFunction request. */ - protected function getCallingFunction() + protected function getCallingFunction($depth = 2) { $backtrace = debug_backtrace(); - // Index will always be 2 because 0 is this function and 1 will be the - // function that asked for the calling function. - return $backtrace[2]['function']; + + return $backtrace[$depth]['function']; } }