ExecuteHelper.php 852 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace common\helpers;
  3. use yii\web\NotFoundHttpException;
  4. /**
  5. * Class ExecuteHelper
  6. * @package common\helpers
  7. * @author jianyan74 <751393839@qq.com>
  8. */
  9. class ExecuteHelper
  10. {
  11. /**
  12. * @param string $classPath 实例化类名路径
  13. * @param string $method 方法
  14. * @param array|object $params 参数
  15. * @throws NotFoundHttpException
  16. */
  17. public static function map($classPath, $method, $params)
  18. {
  19. if (!class_exists($classPath)) {
  20. throw new NotFoundHttpException($classPath . '未找到');
  21. }
  22. /* @var $class \common\interfaces\AddonWidget */
  23. $class = new $classPath;
  24. if (!method_exists($class, $method)) {
  25. throw new NotFoundHttpException($classPath . '/' . $method . ' 方法未找到');
  26. }
  27. return $class->run($params);
  28. }
  29. }
粤ICP备19079148号