For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
预约演示登录免费开始
  • 使用 SDK
    • SDK 概述
    • SDK 如何工作
    • Quickstart
    • Customer showcase
  • 使用 SDK
    • 项目结构
    • 添加自定义代码
    • Migrating to Replay
    • 功能特性
  • 参考
      • Generating an SDK
      • 发布到 Packagist
      • PHP 配置
      • 添加自定义代码
      • 变更日志
      • Customer showcase
  • 资源
    • generators.yml
Checking status...
SOC2Soc 2 Type II
© 2026 Fern • Birch Solutions, Inc., a Postman company

Documentation

SDKsDocsAsk FernCLI Reference

API Definitions

OpenAPIAsyncAPIOpenRPCgRPC

Resources

BlogSupportPricing

Company

Brand KitPrivacy PolicyTerms of Service
LogoLogo
预约演示登录免费开始
在本页
  • 添加自定义逻辑
  • 添加自定义 SDK 方法
  • 添加自定义依赖项
参考PHP

添加自定义代码

||以 Markdown 格式查看|
此页面是否有帮助?
在仪表板中编辑
上一个

PHP 配置

下一个

Changelog

本页面介绍如何为您的 PHP SDK 添加自定义逻辑、方法和依赖项。

These steps cover adding a new custom file to the SDK. To preserve line-level edits to a generated file, use Replay instead.

添加自定义逻辑

开始添加自定义代码:

1

创建新文件并添加您的自定义逻辑

src/Helper.php
1<?php
2
3namespace YourNamespace;
4
5class Helper
6{
7 public static function myHelper(): void
8 {
9 echo "Hello World!";
10 }
11}
2

将您的文件添加到 .fernignore

.fernignore
1# Specify files that shouldn't be modified by Fern
2
3src/Helper.php
3

使用辅助方法

Now your users can consume the helper function by importing it from the SDK.

1<?php
2
3use YourNamespace\Helper;
4
5Helper::myHelper();

添加自定义 SDK 方法

Fern also allows you to add custom methods to the SDK itself (e.g. client.my_method() ) by inheriting the Fern generated client and then extending it.

1

更新 generators.yml 配置

将您的 Fern 生成的客户端命名为类似 BaseClient 的名称,以反映此客户端将被扩展。

generators.yml
1- name: fernapi/fern-php-sdk
2 version: 2.9.0
3 config:
4 clientName: BaseClient
2

导入并扩展生成的客户端

首先,导入 Fern 生成的基础客户端并扩展它。然后,添加您想要的任何方法。

src/MyClient.php
1<?php
2
3namespace YourNamespace;
4
5class MyClient extends BaseClient
6{
7 public function myHelper(): void
8 {
9 echo "Hello World!";
10 }
11}
3

更新 .fernignore

将 MyClient.php 添加到 .fernignore。

.fernignore
1+ src/MyClient.php
4

使用方法

您的用户将构造扩展的客户端,而不是构造生成的客户端。

1<?php
2
3use YourNamespace\MyClient;
4
5$client = new MyClient();

Now your users can consume the helper function by importing it from the SDK.

1$client->myHelper();

添加自定义依赖项

要添加您的自定义代码所需的包,请使用 composerJson 配置选项更新您的 generators.yml。

generators.yml
1- name: fernapi/fern-php-sdk
2 version: 2.9.0
3 config:
4 composerJson:
5 require:
6 guzzlehttp/guzzle: "^7.0"
7 require-dev:
8 phpunit/phpunit: "^10.0"