当前位置: 首页>>代码示例>>PHP>>正文


PHP Reflection::ValidateMethodReturnValue方法代码示例

本文整理汇总了PHP中Reflection::ValidateMethodReturnValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Reflection::ValidateMethodReturnValue方法的具体用法?PHP Reflection::ValidateMethodReturnValue怎么用?PHP Reflection::ValidateMethodReturnValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Reflection的用法示例。


在下文中一共展示了Reflection::ValidateMethodReturnValue方法的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;
 }
开发者ID:pluginscart,项目名称:Pak-PHP,代码行数:51,代码来源:Reflection.php


注:本文中的Reflection::ValidateMethodReturnValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。