fusio / sdk-laravel
用于将Fusio集成到您的Laravel应用程序的SDK
v0.2.3
2022-08-06 21:06 UTC
Requires
- fusio/sdk: ^2.0
- laravel/framework: ^7.0|^8.0|^9.0
Requires (Dev)
- vimeo/psalm: ^4.0
README
该库将 Fusio SDK 集成到Laravel中。这意味着您可以通过Laravel应用程序完全控制Fusio后端API。还有一个 Laravel示例应用程序,展示了如何使用此SDK。
配置
为了访问API,您需要在配置中提供 base_uri
、app_key
和 app_secret
。默认情况下,我们从配置中加载这些数据。
使用方法
后端
创建操作
$config = new \Fusio\Sdk\Backend\Action_Config(); $config['response'] = \json_encode(['hello' => 'world']); $action = new \Fusio\Sdk\Backend\Action_Create(); $action->setName('my-new-action'); $action->setClass('Fusio\Adapter\Util\Action\UtilStaticResponse'); $action->setConfig($config); $response = FusioClient::backend()->getBackendAction()->backendActionActionCreate($action); echo $response->getMessage() . "\n";
创建应用
$app = new \Fusio\Sdk\Backend\App_Create(); $app->setStatus(1); $app->setUserId(1); $app->setName('my-new-action'); $app->setUrl('https://myapp.com'); $app->setScopes(['foo', 'bar']); $response = FusioClient::backend()->getBackendApp()->backendActionAppCreate($app); echo $response->getMessage() . "\n";
创建路由
$get = new \Fusio\Sdk\Backend\Route_Method(); $get->setActive(true); $get->setPublic(true); $get->setDescription('My GET description'); $get->setOperationId('my_get_operation_id'); $get->setResponse('My_Response_Schema'); $get->setAction('My_Action'); $methods = new \Fusio\Sdk\Backend\Route_Methods(); $methods['GET'] = $get; $version = new \Fusio\Sdk\Backend\Route_Version(); $version->setVersion(1); $version->setStatus(1); $version->setMethods($methods); $route = new \Fusio\Sdk\Backend\Route_Create(); $route->setPath('/new/path'); $route->setController('Fusio\Impl\Controller\SchemaApiController'); $route->setConfig([$version]); $response = FusioClient::backend()->getBackendRoutes()->backendActionRouteCreate($route); echo $response->getMessage() . "\n";
获取路由
$entries = FusioClient::backend()->getBackendRoutes()->backendActionRouteGetAll(null)->getEntry(); foreach ($entries as $entry) { echo $entry->getPath() . "\n"; }
消费者
更改密码
$changePassword = new \Fusio\Sdk\Consumer\Account_ChangePassword(); $changePassword->setOldPassword('test1234'); $changePassword->setNewPassword('test1234!'); $changePassword->setVerifyPassword('test1234!'); $response = FusioClient::consumer()->getConsumerAccountChangePassword()->consumerActionUserChangePassword($changePassword); echo $response->getMessage() . "\n";