melisplatform/melis-platform-frameworks

Melis 平台框架

安装: 952

依赖: 11

建议者: 0

安全性: 0

星星: 1

观察者: 7

分支: 0

开放问题: 0

类型:melisplatform-module

v5.2.1 2024-08-13 08:34 UTC

README

此模块处理第三方框架的执行并返回请求的响应内容,它还提供了一个服务,以便对第三方进行请求。

先决条件

此模块需要安装 melisplatform/melis-core。当使用 composer 时,这将自动完成。

安装

composer require melisplatform/melis-platform-frameworks

添加第三方框架

第三方框架位于 Melis 平台应用的根目录 /thirdparty 中,在此目录中您可以放置所需的框架。
Melis 平台框架的框架骨架可以在此处下载
LaravelSymfonyLumenSilex

...
/module
/public
/storage
/test
/thirdparty
    /Laravel
        /app
        /bootstrap
        /config
        ...
    /Symfony
        /bin
        /config
        /public
        ...
...

以上是在 /thirdparty 目录中添加 Laravel 和 Symfony 框架的示例。
注意:您可以选择框架目录的名称,然后在下面的配置中应用。

第三方框架执行

在执行第三方框架时,必须在配置文件中声明配置数据,以确定要执行的应用程序,这可以通过在配置文件中添加此数据数组来完成

'third-party-framework' => [
    'index-path' => [
        'Laravel/public/index.php'
    ]
],

'index-path' 必须设置根目录中 /thirdparty 内应用程序 index.php 文件的路径。例如 'Laravel/public/index.php'。不要将 /thirdparty 目录包含在路径中。

第三方框架修改

框架响应必须修改为返回响应内容和请求状态,以下是一个将 Laravel 框架作为第三方框架集成的示例。

Laravel public/index.php

public/index.php 文件的最后部分,Laravel 通过调用 Response 对象的 $response->send() 方法来生成响应,然后通过 $kernel->terminate($request, $response) 终止应用程序,如下所示

...

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

在第三方框架集成中,不是在 index.php 文件中显示响应和终止应用程序,这将返回一个包含使用 getContent()getStatusCode()Response 对象获取的内容和状态的数组。

...

// $response->send();

// $kernel->terminate($request, $response);

return [
    'statusCode' => $response->getStatusCode(),
    'content' => $response->getContent(),
];

注意 $response->send()$kernel->terminate($request, $response) 已注释以避免渲染响应和终止应用程序。

服务和实现

此模块有一个 MelisPlatformService 服务,用于调用以从第三方框架获取响应。通过指定请求的路由,它将执行请求并返回结果内容。

示例

$thirdPartySrv = $this->getServiceManager()->get('MelisPlatformService');
$thirdPartySrv->setRoute('/melis/lravel-list');
$response = $thirdPartySrv->getContent();

作者

还可以查看参与此项目的 贡献者 列表。

许可

本项目采用 OSL-3.0 许可证 - 详细信息请参阅 LICENSE.md 文件。