xp-framework/rfc — Issue #170: Make Specifying nonexistant classpaths fatal
Author: kiesel
Created: 2011-10-17 16:02:36+00:00
State: closed
Labels: framework, implemented

Scope of Change
====
Make having a classpath part to a XAR file or directory that actually
does not exist or is not readable a fatal error.

Rationale
====
Classpaths (or "include_path"s) are specified to change the order of
and enhance the class loading process. A path within the classpaths that
does not exist does not serve any useful purpose, but is usually a
indicator of a simple mistake, which should be detected early.

The XP framework should follow the paradigma "bail out early".

By not bailing out before running the program, error detection will
be made much harder at a later stage.

Functionality
====

Patch
----

```
Index: skeleton/lang.base.php
===================================================================
====
+++ skeleton/lang.base.php (working copy)
@@ -526,7 +526,7 @@
// Registry initialization
xp::$registry['null']= new null();
xp::$registry['loader']= new xp();
- xp::$registry['classpath']= array_filter(array_map('realpath', explode(PATH_SEPARATOR, get_include_path())));
+ xp::$registry['classpath']= explode(PATH_SEPARATOR, get_include_path());

// Register stream wrapper for .xar class loading
stream_wrapper_register('xar', 'xarloader');
Index: skeleton/lang/ClassLoader.class.php
===================================================================
====
+++ skeleton/lang/ClassLoader.class.php (working copy)
@@ -55,10 +55,13 @@

// Scan include-path, setting up classloaders for each element
foreach (xp::$registry['classpath'] as $element) {
- if (is_dir($element)) {
- self::registerLoader(FileSystemClassLoader::instanceFor($element, FALSE));
- } else if (is_file($element)) {
- self::registerLoader(ArchiveClassLoader::instanceFor($element, FALSE));
+ $resolved= realpath($element);
+ if (is_dir($resolved)) {
+ self::registerLoader(FileSystemClassLoader::instanceFor($resolved, FALSE));
+ } else if (is_file($resolved)) {
+ self::registerLoader(ArchiveClassLoader::instanceFor($resolved, FALSE));
+ } else {
+ xp::error('[bootstrap] Classpath element ['.$element.'] not found');
}
}
}

```

Security considerations
====

Speed impact
====

Dependencies
====

Related documents
====