MDL-48498 core_files: curl_security_helper_base and implementation

Base class and core implementation providing a means to check URLs
against the curl security admin settings entries.
This commit is contained in:
Jake Dallimore
2016-11-08 15:11:15 +08:00
parent 067268942c
commit f6d9efefaa
4 changed files with 611 additions and 0 deletions
+23
View File
@@ -839,4 +839,27 @@ class phpunit_util extends testing_util {
}
}
}
/**
* Helper function to call a protected/private method of an object using reflection.
*
* Example 1. Calling a protected object method:
* $result = call_internal_method($myobject, 'method_name', [$param1, $param2], '\my\namespace\myobjectclassname');
*
* Example 2. Calling a protected static method:
* $result = call_internal_method(null, 'method_name', [$param1, $param2], '\my\namespace\myclassname');
*
* @param object|null $object the object on which to call the method, or null if calling a static method.
* @param string $methodname the name of the protected/private method.
* @param array $params the array of function params to pass to the method.
* @param string $classname the fully namespaced name of the class the object was created from (base in the case of mocks),
* or the name of the static class when calling a static method.
* @return mixed the respective return value of the method.
*/
public static function call_internal_method($object, $methodname, array $params = array(), $classname) {
$reflection = new \ReflectionClass($classname);
$method = $reflection->getMethod($methodname);
$method->setAccessible(true);
return $method->invokeArgs($object, $params);
}
}