Skip to content

Module Dependencies #204

@thekid

Description

@thekid

Scope of Change

Module dependency support will be added to the XP Framework. Modules as defined in RFC #220 are a group of types and resources with added metadata and optional initialization code.

Rationale

Take for example an application that someone has written using the XP Framework and wants to make it available for the public to use. This application uses a certain version of the framework (or a range, such as "5.9-SERIES"), but also depends on a certain module which is not part of the framework but the app's author himself has written and made
available as a separate download. The following questions arise:

  • How is the dependency on the library tracked?
  • How is the framework version verified?

Functionality

At the moment, this would probably be accomplished by checking the framework version comparing against xp::version() and then verifying the dependencies are loaded using module reflection, maybe checking against an annotation. This would be a possible implementation:

<?php
  module imaging(1.0.0) {
    private static $dependencies= array(
      'parellels' => '1.0.5'
      'core' => '5.9*'
    );

    static function __static() {
      foreach (self::$dependencies as $module => $constraint) {
        $version= Module::forName($module)->getVersion();
        $l= strlen($constraint)- 1;
        if ('*' === $constraint{$l}) {
          $result= version_compare($version, substr($constraint, 0, -1), 'ge');
        } else if ('+' === $constraint{$l}) {
          $result= version_compare($version, substr($constraint, 0, -1), 'gt');
        } else {
          $result= version_compare($version, $constraint, 'eq');
        } 
        if (!$result) throw new IllegalStateException('Dependency '.$module.'('.$constraint.') not met');
      }
    }
  }
?>

This RFC will standardize this procedure.

Defining dependencies

Dependencies are expressed via requires statement containing a list of dependencies:

<?php
  module imaging(0.1.1) requires parallels(1.0.5), core(5.9.0*) {
  }
?>

The following rules apply for the dependency version:

  • 5.9.0+ => must be greater than 5.9.0
  • 5.9.0* => must be greater than or equal to 5.9.0
  • 5.9.0 => must be equal to 5.9.0

Reflection

<?php
  $module= Module::forName('imaging');
  $dependencies= $module->getDependencies();   // array('parallels' => '1.0.5', 'core' => '5.9.0*')
?>

Security considerations

Speed impact

Dependencies

RFC #220

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