# @bref\.sh/constructs 中文文档

规范地址：https://npmcn.com/package/%40bref.sh/constructs/

版本：2\.0\.6
npm 元数据更新时间：2026-10-21T14:21:36.265Z
中文译文更新时间：2026-11-08T14:36:52.357Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40bref.sh/constructs
原文对照：https://npmcn.com/package/%40bref.sh/constructs/?lang=original
项目主页：https://github.com/brefphp/constructs#readme
源码仓库：https://github.com/brefphp/constructs

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：22.9 kB，25 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- peer 依赖：constructs ^10\.0\.0，aws-cdk-lib ^2\.100\.0
- 首次发布：2022-12-15T14:59:22.290Z
- 最新版本发布：2026-10-21T14:21:35.509Z
- 近 30 天下载量：7793（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：12（近 12 个月 2 个）

## 中文简介

这个 [布莱夫](https://bref.sh/) CDK构建允许您使用 AWS CDK 在 AWS Lambda 上部署无服务器的 PHP 应用程序 .

## 安装

```sh
npm install @bref.sh/constructs
```

也可以使用：`pnpm add @bref.sh/constructs`、`yarn add @bref.sh/constructs`、`bun add @bref.sh/constructs`

## README

# 在 AWS Lambda 为 PHP 构建 AWS CDK

这个 [布莱夫](https://bref.sh/) CDK构建允许您使用 AWS CDK 在 AWS Lambda 上部署无服务器的 PHP 应用程序 .

默认情况下, Bref [使用无服务器框架部署](https://bref.sh/docs/deploy.html)。使用 AWS CDK 是一个选择,但请注意这是一个高级话题。 如果你迷路了,跟着我 [Bref 文档](https://bref.sh/docs/) 换句话说.

## 安装

安装 [软件包](https://github.com/brefphp/constructs) 与国家预防机制:

```bash
npm install @bref.sh/constructs
```

## 使用量

部署 HTTP 应用程序的简单示例 :

```typescript
import { Construct } from 'constructs';
import { App, Stack } from 'aws-cdk-lib';
import { PhpFpmFunction } from '@bref.sh/constructs';

class MyStack extends Stack {
    constructor(scope: Construct, id: string, props?: StackProps) {
        super(scope, id, props);

        new PhpFpmFunction(this, 'Hello', {
            handler: 'public/index.php',
        });
    }
}

const app = new App();
new MyStack(app, 'test', {
    env: {
        region: 'eu-west-1',
    },
});
```

## 构造

### 职能

#### `PhpFpmFunction`

此构造将 PHP 函数与 [HTTP 运行时间](https://bref.sh/docs/runtimes/http.html)。 。 。 .

```typescript
new PhpFpmFunction(this, 'MyFunction', {
    handler: 'public/index.php',
});
```

它继承自 AWS CDK [`Function` 构造](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html) 默认设置这些选项:

-   `handler`数字 : `index.php` 默认
-   `runtime`数字 : `provided.al2023`
-   `code`:代码自动从当前目录中拉链.
-   `layers`: Bref 层自动添加.
-   `memorySize`数字 : `1024`
-   `timeout`数字 : `28` (单位:秒)

该代码从当前目录中自动被拉链. 您可以通过设置 `code` 属性 :

```typescript
import { packagePhpCode } from '@bref.sh/constructs';

new PhpFpmFunction(this, 'MyFunction', {
    code: packagePhpCode('custom-path', {
        exclude: ['docs'],
    }),
});
```

下列途径始终被排除在外: `.git`, (中文(简体) ), `.idea`, (中文(简体) ), `cdk.out`, (中文(简体) ), `node_modules`, (中文(简体) ), `.bref`, (中文(简体) ), `.serverless`, (中文(简体) ), `tests`。 。 。 .

该建筑还增加了以下选项:

-   `phpVersion` (默认 : `8.4`:要使用的PHP版本.

#### `PhpFunction`

此构造将 PHP 函数与 [“事件驱动的函数”运行时间](https://bref.sh/docs/runtimes/function.html)。 。 。 .

```typescript
new PhpFunction(this, 'MyFunction', {
    handler: 'my-handler.php',
});
```

它继承自 AWS CDK [`Function` 构造](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html) 默认设置这些选项:

-   `runtime`数字 : `provided.al2023`
-   `code`:代码自动从当前目录中拉链.
-   `layers`: Bref 层自动添加.
-   `memorySize`数字 : `1024`
-   `timeout`数字 : `6` (单位:秒)

该代码从当前目录中自动被拉链. 您可以通过设置 `code` 属性 :

```typescript
import { packagePhpCode } from '@bref.sh/constructs';

new PhpFunction(this, 'MyFunction', {
    // ...
    code: packagePhpCode('custom-path', {
        exclude: ['docs'],
    }),
});
```

下列途径始终被排除在外: `.git`, (中文(简体) ), `.idea`, (中文(简体) ), `cdk.out`, (中文(简体) ), `node_modules`, (中文(简体) ), `.bref`, (中文(简体) ), `.serverless`, (中文(简体) ), `tests`。 。 。 .

该建筑还增加了以下选项:

-   `phpVersion` (默认 : `8.4`:要使用的PHP版本.

#### `ConsoleFunction`

此构造将 PHP 函数与 ["控制台"运行时间](https://bref.sh/docs/runtimes/console.html)。 。 。 .

```typescript
new ConsoleFunction(this, 'Artisan', {
    handler: 'artisan',
});
```

它继承自 AWS CDK [`Function` 构造](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html) 默认设置这些选项:

-   `runtime`数字 : `provided.al2023`
-   `code`:代码自动从当前目录中拉链.
-   `layers`: Bref 层自动添加.
-   `memorySize`数字 : `1024`
-   `timeout`数字 : `6` (单位:秒)

该代码从当前目录中自动被拉链. 您可以通过设置 `code` 属性 :

```typescript
import { packagePhpCode } from '@bref.sh/constructs';

new ConsoleFunction(this, 'Artisan', {
    // ...
    code: packagePhpCode('custom-path', {
        exclude: ['docs'],
    }),
});
```

下列途径始终被排除在外: `.git`, (中文(简体) ), `.idea`, (中文(简体) ), `cdk.out`, (中文(简体) ), `node_modules`, (中文(简体) ), `.bref`, (中文(简体) ), `.serverless`, (中文(简体) ), `tests`。 。 。 .

该建筑还增加了以下选项:

-   `phpVersion` (默认 : `8.4`:要使用的PHP版本.

## 常见问题

### @bref\.sh/constructs 是什么？

这个 布莱夫 CDK构建允许您使用 AWS CDK 在 AWS Lambda 上部署无服务器的 PHP 应用程序 \.

### 如何安装 @bref\.sh/constructs？

在项目目录运行 npm install @bref\.sh/constructs，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：constructs（^10\.0\.0）、aws-cdk-lib（^2\.100\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @bref\.sh/constructs 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @bref\.sh/constructs 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @bref\.sh/constructs 可以商用吗？

@bref\.sh/constructs 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @bref\.sh/constructs 的下载量有多少？

根据 npm 官方下载统计，@bref\.sh/constructs 在 2026/10/09 – 2026/11/07 这 30 天内被下载 7,793 次，日均约 260 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @bref\.sh/constructs 还在维护吗？

最新版本 2\.0\.6 发布于 2026/10/21（18 天前）；至今共发布 12 个版本，其中过去 12 个月发布了 2 个；首次发布于 2022/12/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

