Problem
#106 defines phpc.json for binary / serve --aot, but multi-file apps (#67, #210) need PSR-4 autoloading (App\Router in src/Router.php). Today contributors must manual require every file or rely on host PHP spl_autoload only at compile time.
Without a manifest autoload story, examples/003-MiniWebApp cannot use namespaced src/ cleanly.
Goal
Manifest keys:
{
"public": "public",
"entry": "public/index.php",
"autoload": {
"psr-4": { "App\\": "src/" }
},
"includes": ["config.php"]
}
phpc serve / bin/vm.php project mode resolves classes before compile/run.
Implementation hints
Phase A — VM serve (compile-time)
- Extend
lib/Web/ProjectManifest.php to parse autoload + includes.
- Before
Runtime::parseAndCompile, register a compile-time autoloader:
- Map
App\ prefix → src/ relative to project root
require_once on class file when referenced (host PHP is fine for discovery)
includes: require_once each path in order (for config.php constants).
Phase B — AOT (harder)
Phase C — Docs + example
Tasks
Acceptance criteria
{ "autoload": { "psr-4": { "App\\": "src/" } } }
./phpc serve 127.0.0.1:8080 examples/003-MiniWebApp
curl 'http://127.0.0.1:8080/index.php'
App\Router resolves without manual require in public/index.php.
Verification (local only)
./script/ci-local.sh --filter ProjectManifest
docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev ./phpc lint examples/003-MiniWebApp/public/index.php
Dependencies
Related
Files
lib/Web/ProjectManifest.php, bin/serve.php, bin/phpc.php, docs/phpc-json.md
Problem
#106 defines
phpc.jsonforbinary/ serve --aot, but multi-file apps (#67, #210) need PSR-4 autoloading (App\Routerinsrc/Router.php). Today contributors must manualrequireevery file or rely on host PHPspl_autoloadonly at compile time.Without a manifest autoload story,
examples/003-MiniWebAppcannot use namespacedsrc/cleanly.Goal
Manifest keys:
{ "public": "public", "entry": "public/index.php", "autoload": { "psr-4": { "App\\": "src/" } }, "includes": ["config.php"] }phpc serve/bin/vm.phpproject mode resolves classes before compile/run.Implementation hints
Phase A — VM serve (compile-time)
lib/Web/ProjectManifest.phpto parseautoload+includes.Runtime::parseAndCompile, register a compile-time autoloader:App\prefix →src/relative to project rootrequire_onceon class file when referenced (host PHP is fine for discovery)includes:require_onceeach path in order (forconfig.phpconstants).Phase B — AOT (harder)
includeslistincludeslisting allsrc/*.phpuntil static analysis existsPhase C — Docs + example
docs/phpc-json.mdschema"autoload": { "App\\": "src/" }Tasks
docs/phpc-json.md)bin/serve.php/phpc serveincludesarray loaded once per requestphpc lintrespects autoload when lintingpublic/index.phpexamples/003-MiniWebAppAcceptance criteria
{ "autoload": { "psr-4": { "App\\": "src/" } } }./phpc serve 127.0.0.1:8080 examples/003-MiniWebApp curl 'http://127.0.0.1:8080/index.php'App\Routerresolves without manualrequireinpublic/index.php.Verification (local only)
./script/ci-local.sh --filter ProjectManifest docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev ./phpc lint examples/003-MiniWebApp/public/index.phpDependencies
Related
Files
lib/Web/ProjectManifest.php,bin/serve.php,bin/phpc.php,docs/phpc-json.md