-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge module.xp and autoload.php #319
Comments
TransitionThis describes the various filesystem layouts and where module definitions are loaded from. TL;DR: If you don't use modules, no need for any action. If you do:
Basic LayoutContains src/main/php/autoload.php
Classic module layoutContains src/main/php/autoload.php and src/main/php/module.xp
New module layoutContains src/main/php/autoload.php which defines $module.
BC module layoutContains src/main/php/autoload.php which defines $module and src/main/php/module.xp for BC reasons. Note you need to maintain the module code twice in both files!
|
Example of transition to new functionality: diff --git a/src/main/php/autoload.php b/src/main/php/autoload.php
index 832c1dd..89375e3 100755
--- a/src/main/php/autoload.php
+++ b/src/main/php/autoload.php
@@ -1,3 +1,18 @@
-<?php namespace xp;
+<?php namespace xp\compiler;
-\lang\ClassLoader::registerPath(__DIR__);
\ No newline at end of file
+use lang\ClassLoader;
+use lang\reflect\Package;
+
+define('MODIFIER_PACKAGE', 2048);
+define('MODIFIER_INLINE', 4096);
+define('MODIFIER_NATIVE', 8192);
+define('DETAIL_PROPERTY', 0);
+
+ClassLoader::registerPath(__DIR__, false, 'xp-framework/compiler', [
+
+ /** @return void */
+ 'initialize' => function() {
+ Syntax::registerAll(Package::forName('xp.compiler.syntax')->getPackages());
+ ClassLoader::registerLoader(JitClassLoader::instanceFor(realpath('.')), true);
+ }
+]); |
For phase 2, the $ git diff
diff --git a/src/main/php/xp/runtime/Version.class.php b/src/main/php/xp/runtime/Version.class.php
index c210000..7d950b1 100755
--- a/src/main/php/xp/runtime/Version.class.php
+++ b/src/main/php/xp/runtime/Version.class.php
@@ -1,6 +1,7 @@
<?php namespace xp\runtime;
use util\cmd\Console;
+use lang\reflect\Module;
/**
* Displays XP version and runtime information
@@ -43,15 +44,15 @@ class Version {
public static function main(array $args) {
if (empty($args)) {
Console::writeLinef(
- 'XP %s { PHP %s & ZE %s } @ %s',
+ "\e[37;1mXP %s { PHP %s & ZE %s } @ %s\e[0m",
\xp::version(),
phpversion(),
zend_version(),
php_uname()
);
- Console::writeLine('Copyright (c) 2001-2016 the XP group');
- foreach (\lang\ClassLoader::getLoaders() as $delegate) {
- Console::writeLine($delegate->toString());
+ Console::writeLine('Copyright (c) 2001-2017 the XP group');
+ foreach (Module::$registered as $module) {
+ Console::writeLine($module->name(), "\e[32m: ", $module->classLoader()->toString(), "\e[0m");
}
return 1;
} else { |
💡 How about also moving <?php namespace com\example;
use lang\ClassLoader;
ClassLoader::registerPath('src/main/php', false,'xp-forge/patterns', [
'initialize' => function() {
echo '(autoload.php) Loaded module ', $this->name(), "\n";
}
]); |
Libraries cannot drop module.xp until they require - "xp-framework/core": "^9.0 | ^8.0 | ^7.0"
+ "xp-framework/core": "^9.0 | ^8.3 | ^7.9" ...and still support XP7 - it's the last version with PHP 5.6 support, necessary for running on Debian Jessie, which bundles this version of PHP by default. |
It wouldn't be picked up by direct references via class.pth, then: # Include this library
../inject/src/main/php/ So first we should either start putting module references there, see xp-runners/main#5 or reference autoload.php directly # Local path and file references
src/autoload.php
# Dependencies, composer-style
?vendor/autoload.php
# Directly referencing dependencies, e.g. during development
../xp/inject/src/autoload.php The autoload.php files would then: <?php namespace inject;
use lang\ClassLoader;
ClassLoader::registerPath('src/main/php', false, 'xp-forge/inject', [
'initialize' => function() {
echo '(autoload.php) Loaded module ', $this->name(), "\n";
}
]);
ClassLoader::registerPath('src/test/php', false, 'xp-forge/inject@test'); |
...or maybe even a file <?php namespace inject;
use lang\ClassLoader;
ClassLoader::registerModule(__DIR__, 'xp-forge/inject', ['main/php', 'test/php'], [
'initialize' => function() {
echo '(autoload.php) Loaded module ', $this->name(), "\n";
}
]); |
Scope of Change
This RFC suggests merging the special file
module.xp
into autoload.php created for Composer loading purposes.Rationale
.xp
source code from XP Compiler (phase 2)Functionality
Current situation
Typical autoload.php file:
An example module.xp:
Implementation
Code inside autoload.php
Loading
autoload.php
is loaded viaautoload -> files
from composer.jsonautoload.php
would be discovered when registering a path. If a module definition is existant, nomodule.xp
file 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
The text was updated successfully, but these errors were encountered: