psr-overview-knowledge
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "psr-overview-knowledge":https://skillpi.com/zh/skills/deepskill-3f7bd7cc067714240ca9f76477502f05462397eafd870691110d417aa777b5a0。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
PHP 标准建议(PSR)知识库概览。提供所有已采纳 PSR 的全面参考(包括 PSR-1、3、4、6、7、11、12、13、14、15、16、17、18、20),用于 PSR 选择决策与合规性审计。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: psr-overview-knowledge
description: PHP Standards Recommendations (PSR) overview knowledge base. Provides comprehensive reference for all accepted PSRs including PSR-1,3,4,6,7,11,12,13,14,15,16,17,18,20. Use for PSR selection decisions and compliance audits.PSR Overview Knowledge
What is PSR?
PSR (PHP Standards Recommendations) are specifications published by the PHP Framework Interoperability Group (PHP-FIG). They establish common standards for PHP code to ensure interoperability between frameworks and libraries.
Accepted PSRs Summary
| PSR | Name | Category | Status |
|---|---|---|---|
| PSR-1 | Basic Coding Standard | Coding Style | Accepted |
| PSR-3 | Logger Interface | Logging | Accepted |
| PSR-4 | Autoloader | Autoloading | Accepted |
| PSR-6 | Caching Interface | Caching | Accepted |
| PSR-7 | HTTP Message Interface | HTTP | Accepted |
| PSR-11 | Container Interface | DI Container | Accepted |
| PSR-12 | Extended Coding Style | Coding Style | Accepted |
| PSR-13 | Hypermedia Links | Hypermedia | Accepted |
| PSR-14 | Event Dispatcher | Events | Accepted |
| PSR-15 | HTTP Handlers | HTTP | Accepted |
| PSR-16 | Simple Cache | Caching | Accepted |
| PSR-17 | HTTP Factories | HTTP | Accepted |
| PSR-18 | HTTP Client | HTTP | Accepted |
| PSR-20 | Clock | Time | Accepted |
PSR Categories
Coding Style (PSR-1, PSR-12)
Standards for writing clean, consistent PHP code.
| Aspect | PSR-1 | PSR-12 |
|---|---|---|
| Scope | Basic rules | Extended formatting |
| File encoding | UTF-8 without BOM | Inherits PSR-1 |
| Class names | StudlyCaps | Inherits PSR-1 |
| Method names | camelCase | Inherits PSR-1 |
| Indentation | - | 4 spaces |
| Line length | - | 120 chars soft limit |
| Keywords | - | Lowercase |
Autoloading (PSR-4)
Standard for autoloading classes from file paths.
Namespace Prefix → Base Directory
App\ → src/
FQCN → File Path
App\Domain\User\Entity\User → src/Domain/User/Entity/User.php
HTTP (PSR-7, PSR-15, PSR-17, PSR-18)
Standards for HTTP messages, handlers, factories, and clients.
| PSR | Purpose | Key Interfaces |
|---|---|---|
| PSR-7 | HTTP Messages | RequestInterface, ResponseInterface, StreamInterface |
| PSR-15 | HTTP Handlers | MiddlewareInterface, RequestHandlerInterface |
| PSR-17 | HTTP Factories | RequestFactoryInterface, ResponseFactoryInterface |
| PSR-18 | HTTP Client | ClientInterface |
PSR-17 (Factory) → PSR-7 (Message) → PSR-15 (Handler) → PSR-7 (Response)
↓
PSR-18 (Client)
Caching (PSR-6, PSR-16)
Standards for caching implementations.
| Aspect | PSR-6 | PSR-16 |
|---|---|---|
| Complexity | Full-featured | Simple |
| Key interfaces | CacheItemPoolInterface, CacheItemInterface |
CacheInterface |
| Deferred saves | Yes | No |
| Use case | Complex caching needs | Simple get/set |
Logging (PSR-3)
Standard for logging libraries.
interface LoggerInterface {
public function emergency(string|\Stringable $message, array $context = []): void;
public function alert(string|\Stringable $message, array $context = []): void;
public function critical(string|\Stringable $message, array $context = []): void;
public function error(string|\Stringable $message, array $context = []): void;
public function warning(string|\Stringable $message, array $context = []): void;
public function notice(string|\Stringable $message, array $context = []): void;
public function info(string|\Stringable $message, array $context = []): void;
public function debug(string|\Stringable $message, array $context = []): void;
public function log(mixed $level, string|\Stringable $message, array $context = []): void;
}
DI Container (PSR-11)
Standard for dependency injection containers.
interface ContainerInterface {
public function get(string $id): mixed;
public function has(string $id): bool;
}
Events (PSR-14)
Standard for event dispatching.
interface EventDispatcherInterface {
public function dispatch(object $event): object;
}
interface ListenerProviderInterface {
public function getListenersForEvent(object $event): iterable;
}
interface StoppableEventInterface {
public function isPropagationStopped(): bool;
}
Hypermedia (PSR-13)
Standard for hypermedia links (HATEOAS).
interface LinkInterface {
public function getHref(): string;
public function isTemplated(): bool;
public function getRels(): array;
public function getAttributes(): array;
}
Time (PSR-20)
Standard for clock abstraction.
interface ClockInterface {
public function now(): DateTimeImmutable;
}
When to Use Each PSR
Decision Matrix
| Need | PSR |
|---|---|
| Code formatting | PSR-1, PSR-12 |
| Class autoloading | PSR-4 |
| Logging | PSR-3 |
| Simple caching (get/set) | PSR-16 |
| Complex caching (pools, tags) | PSR-6 |
| HTTP requests/responses | PSR-7 |
| HTTP middleware | PSR-15 |
| Creating HTTP objects | PSR-17 |
| HTTP client for external APIs | PSR-18 |
| Dependency injection | PSR-11 |
| Event system | PSR-14 |
| REST API with links | PSR-13 |
| Testing with time | PSR-20 |
Common Combinations
| Use Case | PSRs |
|---|---|
| HTTP API | PSR-7 + PSR-15 + PSR-17 |
| HTTP Client | PSR-7 + PSR-17 + PSR-18 |
| Web Application | PSR-1 + PSR-4 + PSR-12 + PSR-3 + PSR-11 |
| CQRS/Event-Driven | PSR-14 + PSR-3 + PSR-11 |
| Microservice | All of the above |
PHP Package Implementations
PSR-3: Logger
| Package | Description |
|---|---|
monolog/monolog |
De facto standard logger |
psr/log |
Interface only |
PSR-4: Autoloader
| Package | Description |
|---|---|
| Composer | Built-in autoloader |
PSR-6: Cache
| Package | Description |
|---|---|
symfony/cache |
Full-featured cache |
cache/filesystem-adapter |
File-based cache |
PSR-7/PSR-17: HTTP
| Package | Description |
|---|---|
guzzlehttp/psr7 |
Guzzle implementation |
nyholm/psr7 |
Lightweight implementation |
laminas/laminas-diactoros |
Laminas implementation |
PSR-11: Container
| Package | Description |
|---|---|
php-di/php-di |
Autowiring DI container |
league/container |
Flexible container |
pimple/pimple |
Simple container |
PSR-14: Event Dispatcher
| Package | Description |
|---|---|
symfony/event-dispatcher |
Symfony implementation |
league/event |
League implementation |
PSR-15: HTTP Handlers
| Package | Description |
|---|---|
middlewares/utils |
Middleware utilities |
relay/relay |
Simple dispatcher |
PSR-18: HTTP Client
| Package | Description |
|---|---|
guzzlehttp/guzzle |
Full HTTP client |
symfony/http-client |
Symfony HTTP client |
PSR-20: Clock
| Package | Description |
|---|---|
psr/clock |
Interface only |
symfony/clock |
Symfony implementation |
lcobucci/clock |
Simple implementation |
Composer Requirements
{
"require": {
"psr/log": "^3.0",
"psr/cache": "^3.0",
"psr/http-message": "^2.0",
"psr/http-factory": "^1.0",
"psr/http-client": "^1.0",
"psr/container": "^2.0",
"psr/event-dispatcher": "^1.0",
"psr/link": "^2.0",
"psr/clock": "^1.0",
"psr/simple-cache": "^3.0"
}
}
Integration with DDD
Layer Mapping
| DDD Layer | Relevant PSRs | Note |
|---|---|---|
| Domain | PSR-3, PSR-14, PSR-20 | PSR interfaces are pure contracts — acceptable in Domain |
| Application | PSR-3, PSR-11, PSR-14, PSR-20 | Service orchestration layer |
| Infrastructure | PSR-6, PSR-16, PSR-18 | Implementation layer |
| Presentation | PSR-7, PSR-15, PSR-17 | HTTP layer |
Important: PSR packages (
psr/log,psr/clock,psr/event-dispatcher) contain only interfaces — no implementation code. They are PHP community standards equivalent to a standard library. Using PSR interfaces in Domain layer is acceptable and common practice. What is NOT acceptable in Domain: implementation packages likemonolog/monolog,symfony/cache,guzzlehttp/guzzle.
Example: CQRS Application
<?php
declare(strict_types=1);
namespace App\Application\User\Handler;
use App\Application\User\Command\CreateUserCommand;
use App\Domain\User\Entity\User;
use App\Domain\User\Repository\UserRepositoryInterface;
use Psr\EventDispatcher\EventDispatcherInterface; // PSR-14
use Psr\Log\LoggerInterface; // PSR-3
use Psr\Clock\ClockInterface; // PSR-20
final readonly class CreateUserHandler
{
public function __construct(
private UserRepositoryInterface $repository,
private EventDispatcherInterface $eventDispatcher,
private LoggerInterface $logger,
private ClockInterface $clock,
) {
}
public function __invoke(CreateUserCommand $command): void
{
$this->logger->info('Creating user', ['email' => $command->email]);
$user = User::create(
$command->email,
$command->name,
$this->clock->now(),
);
$this->repository->save($user);
foreach ($user->pullEvents() as $event) {
$this->eventDispatcher->dispatch($event);
}
}
}
Compliance Checklist
| PSR | Required For | Check |
|---|---|---|
| PSR-1 | All PHP projects | phpcs --standard=PSR1 |
| PSR-12 | All PHP projects | phpcs --standard=PSR12 |
| PSR-4 | All PHP projects | composer dump-autoload --strict |
| PSR-3 | Projects with logging | Implement LoggerInterface |
| PSR-6/16 | Projects with caching | Implement CacheInterface |
| PSR-7 | HTTP APIs | Use PSR-7 implementations |
| PSR-11 | Projects with DI | Implement ContainerInterface |
| PSR-14 | Event-driven projects | Implement EventDispatcherInterface |
| PSR-15 | HTTP middleware | Implement MiddlewareInterface |
| PSR-17 | HTTP object creation | Use factory interfaces |
| PSR-18 | External API calls | Implement ClientInterface |
| PSR-20 | Time-sensitive code | Implement ClockInterface |
See Also
references/accepted-psrs.md- Detailed PSR descriptionsreferences/when-to-use.md- Decision matrix for PSR selectionreferences/compatibility.md- Inter-PSR relationshipsreferences/php-fig-process.md- How PSRs are createdassets/psr-selection-guide.md- Selection guide template
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 PHP PSR 标准的全面知识库,涵盖所有已采纳 PSR 的详细参考
- 包含实用的决策矩阵和常见组合建议,帮助用户进行 PSR 选择
- 提供主流 PHP 包的实现推荐和 Composer 依赖配置
亮点
- description 明确描述了 Skill 的功能、覆盖范围和用途
- 触发词精准完整,边界清晰,便于用户理解和使用
待提升项
-
文档过长 原报告严重程度:轻微
主文档超过 500 行,建议拆分为多个子文档以提高可读性
改进建议:考虑将文档拆分为多个子文档,如 'psr-basics.md'、'psr-decision-matrix.md'、'psr-implementations.md' 等
-
缺少独立 'When to Use' 章节 原报告严重程度:轻微
'When to Use' 相关内容未使用独立章节标题,建议增加明确的章节划分
改进建议:增加 'When to Use' 独立章节标题,或将相关内容移至更显眼的位置
亮点
- 文档结构清晰,包含多个完整章节和丰富的表格、代码示例
- frontmatter 完整,符合规范要求
亮点
- 内容基于官方 PHP-FIG 标准,信息准确可靠
- 提供合规性检查清单,帮助用户验证 PSR 实施情况
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。