-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Scope of Change
This RFC suggests storing imports in xp::$meta.
Rationale
Faster access when resolving names - instead of having to parse the code again, we can simply reuse what lang.reflect.ClassParser (or the XP Compiler) have already extracted and put there there. Imports are used when resolving types inside apidoc and inside eval keys for annotations.
Functionality
Imports will be stored under a key named "use" (matching the use statement). It contains a map of aliases to qualified names.
Example
namespace org\example;
use util\Date;
use lang\Primitive as P;
use org\example\nodes\{Node, Variable as Var};
class T { ... }This will produce the following:
xp::$meta['org.example.T']['use']= [
'Date' => 'util\Date',
'P' => 'lang\Primitive',
'Node' => 'org\example\nodes\Node',
'Var' => 'org\example\nodes\Variable',
];Security considerations
None
Speed impact
Slightly slower
Dependencies
XP Compiler may optionally be extended to track imports, speeding up reflective access. Currently, it emits use statements which can then later on be tokenized again.
Related documents
- https://github.com/xp-framework/core/blob/v10.5.0/src/main/php/lang/reflect/ClassParser.class.php#L480 - current parsing implementation