basePath . '/plugins/' . $pluginName; if (! is_dir($pluginPath)) { throw new Exception('插件不存在: ' . $pluginName); } $pluginController = ''; $lastKey = count($pluginSegment) - 1; foreach ($pluginSegment as $key => $item) { if ($key == $lastKey) { $pluginController .= ucfirst($item); } else { $pluginController .= $item . '\\'; } } $str = 'app\plugins\%s\controllers\%sController'; if ($is_client) { $str = 'app\plugins\%s\controllers\client\%sController'; } if ($is_alliance) { $str = 'app\plugins\%s\controllers\alliance\%sController'; } $pluginClass = sprintf($str, $pluginName, $pluginController); if (! class_exists($pluginClass)) { throw new Exception('插件类不存在: ' . $pluginClass); } if (! method_exists($pluginClass, $actionName)) { throw new Exception('插件方法不存在: ' . $actionName); } return call_user_func(array(new $pluginClass(Yii::$app->controller->id, Yii::$app->controller->module, ['callback' => $callback]), $actionName)); } catch (\Throwable $throwable) { return [ 'code' => 1, 'msg' => $throwable->getMessage(), 'line' => $throwable->getLine(), 'file' => $throwable->getFile() ]; } } /** * @param $uncamelized_words * @param string $separator * @return string */ private static function camelize($uncamelized_words, $separator = '-'): string { $uncamelized_words = $separator . str_replace($separator, ' ', strtolower($uncamelized_words)); return ltrim(str_replace(' ', '', ucwords($uncamelized_words)), $separator); } }