本文整理汇总了PHP中Reflection::ParseMethodDocBlockComments方法的典型用法代码示例。如果您正苦于以下问题:PHP Reflection::ParseMethodDocBlockComments方法的具体用法?PHP Reflection::ParseMethodDocBlockComments怎么用?PHP Reflection::ParseMethodDocBlockComments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reflection
的用法示例。
在下文中一共展示了Reflection::ParseMethodDocBlockComments方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetClosure
/**
* It returns a closure that calls the given function and validates it
* It allows the function to be called in a safe way
*
* It returns a closure that validates the parameters of the user given function
* It then calls the function
* After that it validates the return value of the function
* In case of validation errors, the closure displays an error message and ends script execution
*
* @since 1.0.0
*
* @return object $closure an object of class Closure is returned. The closure function calls the given function with the given parameters
*/
public static final function GetClosure()
{
/** The closure that validates and calls the user given function */
$closure = function ($class_object, $function_name, $parameters, $application_context, $custom_validation_callback) {
/** The reflection object is created. It provides the functions for parsing comments */
$reflection = new Reflection();
/** The parsed method comments */
$parsed_comments = $reflection->ParseMethodDocBlockComments($class_object, $function_name);
/** The internal tags. They are extracted using regular expressions */
$interal_tags = $parsed_comments['internal'];
/** The list of allowed application contexts for the method */
$method_context = $interal_tags['context'];
/** The application context is validated */
$validation_result = $reflection->ValidateMethodContext($method_context, $application_context);
/** The validation result is checked */
if ($validation_result['is_valid'] === false) {
throw new \Exception("Invalid method context. Details: " . $validation_result['validation_message']);
}
/** The test function parameters are validated */
$validation_result = $reflection->ValidateMethodParameters($class_object, $function_name, $parameters, $custom_validation_callback);
/** The validation result is checked */
if ($validation_result['is_valid'] === false) {
throw new \Exception("Function parameters could not be validated. Details: " . $validation_result['validation_message']);
}
/** The parameter values are extracted */
$parameters = array_values($parameters);
/** The test function is called */
$result = $class_object->{$function_name}($parameters[0], $parameters[1], $parameters[2], $parameters[3]);
/** The test function return value is validated */
$validation_result = $reflection->ValidateMethodReturnValue($class_object, "AddNumbers", $result, $custom_validation_callback, $parameters);
/** The validation result is checked */
if ($validation_result['is_valid'] === false) {
throw new \Exception("Function return value could not be validated. Details: " . $validation_result['validation_message']);
}
return $result;
};
return $closure;
}