一键导入
writing-file-emitter
Implement a FileEmitter for boost-core to emit a custom file (e.g. .mcp.json, .editorconfig) into the host project during boost:sync.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Implement a FileEmitter for boost-core to emit a custom file (e.g. .mcp.json, .editorconfig) into the host project during boost:sync.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use dependency injection cleanly in PHP applications. Constructor injection, avoiding service locators, what to put in the container.
Add modern PHP code to a legacy 7.x codebase incrementally. Typed properties, readonly, enums — how to introduce them without forcing a big-bang upgrade.
Author a boost.php config file. Covers all five with* methods, when each matters, and what NOT to put in there.
| name | writing-file-emitter |
| description | Implement a FileEmitter for boost-core to emit a custom file (e.g. .mcp.json, .editorconfig) into the host project during boost:sync. |
A FileEmitter is a single-method interface in SanderMuller\BoostCore\Contracts\FileEmitter:
public function emit(SyncContext $ctx): ?EmittedFile;
Return EmittedFile to write a file. Return null to skip (e.g. an
optional dependency isn't installed). Throwing is recorded as errored
and sync continues with other emitters.
The contract is @experimental — the shape may change before v1.0
stable. Pin to an exact boost-core version if you build against this.
namespace YourVendor\YourPackage\Emitters;
use SanderMuller\BoostCore\Contracts\FileEmitter;
use SanderMuller\BoostCore\Sync\EmittedFile;
use SanderMuller\BoostCore\Sync\SyncContext;
final class YourEmitter implements FileEmitter
{
public function emit(SyncContext $ctx): ?EmittedFile
{
if (! $ctx->packages->has('some/required-dep')) {
return null;
}
return new EmittedFile(
relativePath: '.your-config.json',
content: json_encode(['key' => 'value']) . "\n",
);
}
}
In your package's composer.json:
{
"extra": {
"boost": {
"emitters": [
"YourVendor\\YourPackage\\Emitters\\YourEmitter"
]
}
}
}
Emitters are only loaded from allowlisted vendors (per the host's
boost.php withAllowedVendors([]) declaration). Untrusted vendors'
emitters never instantiate.
shouldEmit check. Keep
constructors parameterless and side-effect-free.../,
absolute paths) is rejected by FileWriter. Always emit a relative
path under the project root.$ctx->packages->has(...) results — call them each time. The
SyncContext is read-only and consistent within a single sync.errored result. Either pick distinct paths or use
one emitter that branches internally.SanderMuller\BoostCore\Sync\SyncContext for what's available on $ctxpackage-boost-laravel's McpJsonEmitter for a real working example