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
.xp source 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.php is loaded via autoload -> files from composer.json
- During XP bootstrapping,
autoload.php would be discovered when registering a path. If a module definition is existant, no module.xp file 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.
Related documents
Scope of Change
This RFC suggests merging the special file
module.xpinto autoload.php created for Composer loading purposes.Rationale
.xpsource code from XP Compiler (phase 2)Functionality
Current situation
Typical autoload.php file:
An example module.xp:
Implementation
Code inside autoload.php
Loading
autoload.phpis loaded viaautoload -> filesfrom composer.jsonautoload.phpwould be discovered when registering a path. If a module definition is existant, nomodule.xpfile would be checked for.Phases
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.
Related documents