Skip to content

Merge module.xp and autoload.php #319

@thekid

Description

@thekid

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

  1. XP9.0. No BC breaks exist. You can start using the new layout alongside the old one.
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions