psr-autoloading-knowledge
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "psr-autoloading-knowledge" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-fe74faad8a09c825bfddfb990886032e1ecd1e9353ac090c9e0fb39e6b6e531a. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
PSR-4 autoloading knowledge base for PHP 8.4 projects: describes namespace-to-path mapping rules, relevant composer.json configuration, recommended directory layouts, and a quick reference of common errors, for autoloading audits and project structure reviews.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- PSR-4 autoloading standard knowledge base for PHP 8.4 projects. Provides quick reference for namespace-to-path mapping, composer.json configuration, directory structure, and common mistakes. Use for autoloading audits and project structure reviews.
- Testing
- Not tested
Browse files
Frontmatter
name: psr-autoloading-knowledge
description: PSR-4 autoloading standard knowledge base for PHP 8.4 projects. Provides quick reference for namespace-to-path mapping, composer.json configuration, directory structure, and common mistakes. Use for autoloading audits and project structure reviews.PSR-4 Autoloading Knowledge
Quick Reference
| Concept | Description |
|---|---|
| Namespace Prefix | Maps to a base directory |
| FQCN | Fully Qualified Class Name |
| Path Mapping | Namespace → Directory → File |
Core Concept
PSR-4 defines how to autoload classes from file paths based on their fully qualified class name.
Namespace Prefix → Base Directory
Acme\Log\ → ./src/
FQCN → File Path
Acme\Log\Writer\FileWriter → ./src/Writer/FileWriter.php
Namespace to Path Mapping
The Formula
File Path = Base Directory + (FQCN - Namespace Prefix) + .php
Where:
- Namespace separators (\) → Directory separators (/)
- Class name → File name with .php extension
Examples
| FQCN | Namespace Prefix | Base Directory | File Path |
|---|---|---|---|
App\Entity\User |
App\ |
src/ |
src/Entity/User.php |
App\Domain\User\Entity\User |
App\ |
src/ |
src/Domain/User/Entity/User.php |
Vendor\Package\SubNs\ClassName |
Vendor\Package\ |
lib/ |
lib/SubNs/ClassName.php |
Composer Configuration
Basic Setup
{
"autoload": {
"psr-4": {
"App\\": "src/",
"App\\Tests\\": "tests/"
}
}
}
Multiple Directories
{
"autoload": {
"psr-4": {
"App\\": ["src/", "lib/"]
}
}
}
DDD Project Structure
{
"autoload": {
"psr-4": {
"App\\": "src/",
"App\\Domain\\": "src/Domain/",
"App\\Application\\": "src/Application/",
"App\\Infrastructure\\": "src/Infrastructure/",
"App\\Presentation\\": "src/Presentation/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
}
}
Symfony Bundle Structure
{
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}
Laravel Package Structure
{
"autoload": {
"psr-4": {
"Vendor\\Package\\": "src/"
}
}
}
Directory Structure Examples
Standard DDD Layout
project/
├── composer.json
├── src/
│ ├── Domain/
│ │ └── User/
│ │ ├── Entity/
│ │ │ └── User.php # App\Domain\User\Entity\User
│ │ ├── ValueObject/
│ │ │ └── Email.php # App\Domain\User\ValueObject\Email
│ │ ├── Repository/
│ │ │ └── UserRepositoryInterface.php
│ │ └── Event/
│ │ └── UserCreated.php
│ ├── Application/
│ │ └── User/
│ │ ├── Command/
│ │ │ └── CreateUserCommand.php
│ │ └── Handler/
│ │ └── CreateUserHandler.php
│ ├── Infrastructure/
│ │ └── Persistence/
│ │ └── Doctrine/
│ │ └── UserRepository.php
│ └── Presentation/
│ └── Api/
│ └── Controller/
│ └── UserController.php
└── tests/
└── Unit/
└── Domain/
└── User/
└── Entity/
└── UserTest.php # App\Tests\Unit\Domain\User\Entity\UserTest
Class Examples
// src/Domain/User/Entity/User.php
<?php
declare(strict_types=1);
namespace App\Domain\User\Entity;
use App\Domain\User\ValueObject\Email;
use App\Domain\User\ValueObject\UserId;
final class User
{
// ...
}
// src/Domain/User/ValueObject/Email.php
<?php
declare(strict_types=1);
namespace App\Domain\User\ValueObject;
final readonly class Email
{
// ...
}
Detection Patterns
Find Mismatched Namespaces
# Extract namespace from files and compare with path
for file in $(find src -name "*.php"); do
namespace=$(grep -m1 "^namespace" "$file" | sed 's/namespace //;s/;//')
expected_ns="App\\$(dirname ${file#src/} | tr '/' '\\')"
if [ "$namespace" != "$expected_ns" ]; then
echo "Mismatch: $file"
echo " Found: $namespace"
echo " Expected: $expected_ns"
fi
done
Find Classes Without Namespace
# Files with class but no namespace
grep -rL "^namespace" --include="*.php" src/ | \
xargs grep -l "^class\|^interface\|^trait\|^enum"
Find Incorrect Class Names
# Class name doesn't match filename
for file in $(find src -name "*.php"); do
filename=$(basename "$file" .php)
if ! grep -q "^\(class\|interface\|trait\|enum\) $filename" "$file"; then
echo "Mismatch: $file (expected class/interface/trait/enum $filename)"
fi
done
Validate Composer Autoload
# Dump autoload and check for errors
composer dump-autoload --strict 2>&1 | grep -i "warning\|error"
# Validate composer.json
composer validate --strict
Common Mistakes
1. Namespace vs Path Mismatch
// File: src/Domain/User/Entity/User.php
// BAD: Namespace doesn't match path
namespace App\User\Entity; // Missing "Domain"
// GOOD: Namespace matches path
namespace App\Domain\User\Entity;
2. Class Name vs Filename Mismatch
// File: src/Domain/UserEntity.php
// BAD: Class name doesn't match filename
class User { }
// GOOD: Class name matches filename
class UserEntity { }
3. Case Sensitivity Issues
// File: src/Domain/User/Entity/user.php (lowercase)
// BAD: Will fail on case-sensitive filesystems (Linux)
namespace App\Domain\User\Entity;
class User { }
// GOOD: Filename should be User.php (PascalCase)
4. Missing Trailing Backslash
// BAD: Missing trailing backslash
{
"autoload": {
"psr-4": {
"App": "src/"
}
}
}
// GOOD: Include trailing backslash
{
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}
5. Incorrect Directory Separator
// BAD: Using backslash in path (Windows-only)
{
"autoload": {
"psr-4": {
"App\\": "src\\"
}
}
}
// GOOD: Use forward slash (cross-platform)
{
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}
Verification Commands
# Regenerate autoload files
composer dump-autoload
# Optimize autoload (production)
composer dump-autoload --optimize
# Validate and show issues
composer dump-autoload --strict
# Test class loading
php -r "require 'vendor/autoload.php'; new App\Domain\User\Entity\User();"
PHP-CS-Fixer Rules
<?php
return (new PhpCsFixer\Config())
->setRules([
// PSR-4 related rules
'single_class_element_per_statement' => true,
'single_import_per_statement' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
],
'no_unused_imports' => true,
'fully_qualified_strict_types' => true,
]);
Integration with DDD Layers
Layer Mapping
| Layer | Namespace | Directory |
|---|---|---|
| Domain | App\Domain\{Context}\ |
src/Domain/{Context}/ |
| Application | App\Application\{Context}\ |
src/Application/{Context}/ |
| Infrastructure | App\Infrastructure\ |
src/Infrastructure/ |
| Presentation | App\Presentation\ |
src/Presentation/ |
Component Mapping
| Component | Namespace Pattern | Directory Pattern |
|---|---|---|
| Entity | App\Domain\{Context}\Entity\ |
src/Domain/{Context}/Entity/ |
| Value Object | App\Domain\{Context}\ValueObject\ |
src/Domain/{Context}/ValueObject/ |
| Repository | App\Domain\{Context}\Repository\ |
src/Domain/{Context}/Repository/ |
| Service | App\Domain\{Context}\Service\ |
src/Domain/{Context}/Service/ |
| Command | App\Application\{Context}\Command\ |
src/Application/{Context}/Command/ |
| Query | App\Application\{Context}\Query\ |
src/Application/{Context}/Query/ |
| Handler | App\Application\{Context}\Handler\ |
src/Application/{Context}/Handler/ |
See Also
references/psr-4-standard.md- Full PSR-4 specificationreferences/composer-integration.md- Composer autoload configurationreferences/directory-structure.md- Project structure examplesreferences/antipatterns.md- Common mistakes and fixesassets/report-template.md- Audit report template
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供PSR-4自动加载标准的完整知识库,覆盖命名空间映射、composer配置、目录结构等核心内容
- 包含实用的检测脚本和常见错误排查指南,可直接用于项目审计
- 适用于PHP 8.4项目,具有明确的版本针对性
Highlights
- 触发词精准完整,覆盖PSR-4、自动加载、composer配置等多种变体
- 边界清晰,不会与其他PHP相关Skill混淆
Highlights
- 结构清晰,包含快速参考、核心概念、配置示例、检测模式等完整章节
- 提供端到端示例和实际项目结构,便于理解和应用
- frontmatter完整,文档组织良好
Highlights
- 提供的bash脚本和composer命令参数正确,可直接执行
- 覆盖主要异常情况,如命名空间不匹配、类名不匹配等
- 包含验证命令和PHP-CS-Fixer规则,确保代码质量
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.