-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
Scope of Change
This RFC suggests merging the special file module.xp into autoload.php created for Composer loading purposes.
Rationale
- Consistent autoloading whether Composer is used or not; less I/O for the case it is.
- Syntax-checkable module initialization code
- Removed confusion with
.xpsource code from XP Compiler (phase 2) - Near zero cost for runtime module reflection (once libraries include module definitions)
Functionality
Current situation
Typical autoload.php file:
<?php namespace xp;
\lang\ClassLoader::registerPath(__DIR__);An example module.xp:
<?php namespace com\example;
module xp-forge/example {
public function initialize() {
echo "Loaded module ", $this->name(), "\n";
}
}Implementation
Code inside autoload.php
<?php namespace com\example;
use lang\ClassLoader;
ClassLoader::registerPath(__DIR__, false,'xp-forge/patterns', [
'initialize' => function() {
echo '(autoload.php) Loaded module ', $this->name(), "\n";
}
]);Loading
- During composer loading,
autoload.phpis loaded viaautoload -> filesfrom composer.json - During XP bootstrapping,
autoload.phpwould be discovered when registering a path. If a module definition is existant, nomodule.xpfile would be checked for.
Phases
- XP9.0. No BC breaks exist. You can start using the new layout alongside the old one.
- XP10.0. The file module.xp is deprecated, code needs to be migrated to the new layout
See also Transition below.
Security considerations
n/a
Speed impact
Slightly slower for the non-Composer case, since autoload.php files weren't being loaded.
Dependencies
None.