<commit_before><?php
/* This class is part of the XP framework
 * 
 * $Id$
 */
 
  uses(
    'lang.IClassLoader',
    'lang.FileSystemClassLoader',
    'lang.DynamicClassLoader',
    'lang.archive.ArchiveClassLoader'
  );
  
  /** 
   * Entry point class to loading classes, packages and resources.
   * Keeps a list of class loaders that load classes from the file
   * system, xar archives, memory, or various other places. These
   * loaders are asked for each class loading request, be it via
   * XPClass::forName(), uses(), requests from the Package class,
   * or explicit calls to ClassLoader::getDefault()->loadClass().
   *
   * Given the following code
   * <code>
   *   $class= ClassLoader::getDefault()->loadClass($name);
   * </code>
   * ...and the following include_path setting:
   * <pre>
   *   ".:/usr/local/lib/xp/xp-rt-5.4.0.xar:/home/classes/"
   * </pre>
   * ...the classloader will ask the class loader delegates:
   * <pre>
   * - FileSystemClassLoader(.)
   * - ArchiveClassLoader(/usr/local/lib/xp/xp-rt-5.4.0.xar)
   * - FileSystemClassLoader(/home/classes/)
   * </pre>
   * ...in the stated order. The first delegate to provide the class 
   * will be asked to load it. In case none of the delegates are able
   * to provide the class, a ClassNotFoundException will be thrown.
   * 
   * @test     xp://net.xp_framework.unittest.reflection.ClassLoaderTest
   * @test     xp://net.xp_framework.unittest.reflection.ClassPathTest
   * @test     xp://net.xp_framework.unittest.reflection.ResourcesTest
   * @test     xp://net.xp_framework.unittest.reflection.PackageTest
   * @test     xp://net.xp_framework.unittest.reflection.RuntimeClassDefinitionTest
   * @test     xp://net.xp_framework.unittest.reflection.FullyQualifiedTest
   * @see      xp://lang.XPClass#forName
   * @see      xp://lang.reflect.Package#loadClass
   * @purpose  Class loading
   */
  final class ClassLoader extends Object implements IClassLoader {
    protected static
      $delegates  = array();

    static function __static() {
      xp::$loader= new self();
      
      // Scan include-path, setting up classloaders for each element
      foreach (xp::$classpath as $element) {
        if ('!' === $element{0}) {
          $before  = TRUE;
          $element = substr($element, 1);
        } else {
          $before= FALSE;
        }

        $resolved= realpath($element);
        if (is_dir($resolved)) {
          $cl= FileSystemClassLoader::instanceFor($resolved, FALSE);
        } else if (is_file($resolved)) {
          $cl= ArchiveClassLoader::instanceFor($resolved, FALSE);
        } else {
          xp::error('[bootstrap] Classpath element ['.$element.'] not found');
        }
        isset(self::$delegates[$cl->instanceId()]) || self::registerLoader($cl, $before);
      }
    }
    
    /**
     * Retrieve the default class loader
     *
     * @return  lang.ClassLoader
     */
    public static function getDefault() {
      return xp::$loader;
    }

    /**
     * Register a class loader from a path
     *
     * @param   string element
     * @param   bool before default FALSE whether to register this as the first loader,
     *          NULL wheather to figure out position by inspecting $element
     * @return  lang.IClassLoader the registered loader
     * @throws  lang.ElementNotFoundException if the path cannot be found
     */
    public static function registerPath($element, $before= FALSE) {
      if (NULL === $before && '!' === $element{0}) {
        $before  = TRUE;
        $element = substr($element, 1);
      } else {<commit_msg>- Add current directory if class path element is not fully qualified # See discussion in issue #304<commit_after><?php
/* This class is part of the XP framework
 * 
 * $Id$
 */
 
  uses(
    'lang.IClassLoader',
    'lang.FileSystemClassLoader',
    'lang.DynamicClassLoader',
    'lang.archive.ArchiveClassLoader'
  );
  
  /** 
   * Entry point class to loading classes, packages and resources.
   * Keeps a list of class loaders that load classes from the file
   * system, xar archives, memory, or various other places. These
   * loaders are asked for each class loading request, be it via
   * XPClass::forName(), uses(), requests from the Package class,
   * or explicit calls to ClassLoader::getDefault()->loadClass().
   *
   * Given the following code
   * <code>
   *   $class= ClassLoader::getDefault()->loadClass($name);
   * </code>
   * ...and the following include_path setting:
   * <pre>
   *   ".:/usr/local/lib/xp/xp-rt-5.4.0.xar:/home/classes/"
   * </pre>
   * ...the classloader will ask the class loader delegates:
   * <pre>
   * - FileSystemClassLoader(.)
   * - ArchiveClassLoader(/usr/local/lib/xp/xp-rt-5.4.0.xar)
   * - FileSystemClassLoader(/home/classes/)
   * </pre>
   * ...in the stated order. The first delegate to provide the class 
   * will be asked to load it. In case none of the delegates are able
   * to provide the class, a ClassNotFoundException will be thrown.
   * 
   * @test     xp://net.xp_framework.unittest.reflection.ClassLoaderTest
   * @test     xp://net.xp_framework.unittest.reflection.ClassPathTest
   * @test     xp://net.xp_framework.unittest.reflection.ResourcesTest
   * @test     xp://net.xp_framework.unittest.reflection.PackageTest
   * @test     xp://net.xp_framework.unittest.reflection.RuntimeClassDefinitionTest
   * @test     xp://net.xp_framework.unittest.reflection.FullyQualifiedTest
   * @see      xp://lang.XPClass#forName
   * @see      xp://lang.reflect.Package#loadClass
   * @purpose  Class loading
   */
  final class ClassLoader extends Object implements IClassLoader {
    protected static
      $delegates  = array();

    static function __static() {
      xp::$loader= new self();
      
      // Scan include-path, setting up classloaders for each element
      foreach (xp::$classpath as $element) {
        if ('!' === $element{0}) {
          $before  = TRUE;
          $element = substr($element, 1);
        } else {
          $before= FALSE;
        }

        $resolved= realpath($element);
        if (is_dir($resolved)) {
          $cl= FileSystemClassLoader::instanceFor($resolved, FALSE);
        } else if (is_file($resolved)) {
          $cl= ArchiveClassLoader::instanceFor($resolved, FALSE);
        } else {
          if ('/' !== $element{0} && ':' !== $element{1}) {   // If not fully qualified
            $element.= ' (in '.getcwd().')';
          }
          xp::error('[bootstrap] Classpath element ['.$element.'] not found');
        }
        isset(self::$delegates[$cl->instanceId()]) || self::registerLoader($cl, $before);
      }
    }
    
    /**
     * Retrieve the default class loader
     *
     * @return  lang.ClassLoader
     */
    public static function getDefault() {
      return xp::$loader;
    }

    /**
     * Register a class loader from a path
     *
     * @param   string element
     * @param   bool before default FALSE whether to register this as the first loader,
     *          NULL wheather to figure out position by inspecting $element
     * @return  lang.IClassLoader the registered loader
     * @throws  lang.ElementNotFoundException if the path cannot be found
     */
    public static function registerPath($element, $before= FALSE) {
      if (NULL === $before && '!' === $element{0}) {
        $before  = TRUE;
        $element = substr($element, 1);
      } else {
{'fraction_non_alphanumeric': 0.1276509523166284, 'fraction_numerical': 0.0033770093205457248, 'mean_word_length': 2.5802707930367506, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1551258', 'n_tokens_mistral': 2193, 'n_tokens_neox': 2140, 'n_words': 600}