<commit_before><?php

namespace Doctrine\Common;

/**
 * A class loader used to load class files on demand.
 *
 * Usage recommendation:
 * 1) Use only 1 class loader instance.
 * 2) Set the base paths to your class libraries (including Doctrine's) through
 *    $classLoader->setBasePath($prefix, $basePath);
 *    Example:
 *      $classLoader->setBasePath('Doctrine', '/usr/local/phplibs/doctrine/lib');
 *    Then, when trying to load the class Doctrine\ORM\EntityManager, for example
 *    the classloader will look for /usr/local/phplibs/doctrine/lib/Doctrine/ORM/EntityManager.php
 *
 * 3) DO NOT setCheckFileExists(true). Doing so is expensive in terms of performance.
 * 4) Use an opcode-cache (i.e. APC) (STRONGLY RECOMMENDED).
 * 
 * @since 2.0
 * @author romanb <<EMAIL>>
 */
class ClassLoader
{    
    private $_namespaceSeparator = '\\';
    private $_fileExtension = '.php';
    private $_checkFileExists = false;
    private $_basePaths = array();
    
    public function __construct()
    {
    }
    
    public function setCheckFileExists($bool)
    {
        $this->_checkFileExists = $bool;
    }
    
    public function setClassFileExtension($extension)
    {
        $this->_fileExtension = $extension;
    }
    
    public function setNamespaceSeparator($separator)
    {
        $this->_namespaceSeparator = $separator;
    }
    
    /**
     * Sets a static base path for classes with a certain prefix that is prepended
     * to the path derived from the class itself.
     *
     * @param string $basePath
     */
    public function setBasePath($classPrefix, $basePath)
    {
        $this->_basePaths[$classPrefix] = $basePath;
    }
    
    /**
     * Loads the given class or interface.
     *
     * @param string $classname The name of the class to load.
     * @return boolean TRUE if the class has been successfully loaded, FALSE otherwise.
     */
    public function loadClass($className)
    {
        if (class_exists($className, false) || interface_exists($className, false)) {
            return false;
        }

        $prefix = substr($className, 0, strpos($className, $this->_namespaceSeparator));
        $class = '';
        if (isset($this->_basePaths[$prefix])) {
            $class .= $this->_basePaths[$prefix] . DIRECTORY_SEPARATOR;
        }

        if ($className[0] == '\\') $className = substr($className, 1);

        $class .= str_replace(array($this->_namespaceSeparator, '_'), DIRECTORY_SEPARATOR, $className)
                . $this->_fileExtension;

        if ($this->_checkFileExists) {
            if (!$fh = @fopen($class, 'r', true)) {
                return false;
            }
            @fclose($fh);
        }

        if ($class == 'ForumAvatar.php' || $class == 'ForumUser.php') {
            echo $class . PHP_EOL;
            try {
                throw new \Exception();
            } catch (\Exception $e) {
                echo $e->getTraceAsString();
            }
        } else if ($class == 'Doctrine/Common/Exceptions/DoctrineException.php') {
            try {
                throw new \Exception();
            } catch (\Exception $e) {
                echo $e->getTraceAsString();
            }
        }

        require $class;
        
        return true;
    }
    
    /**
     * Registers this class loader using spl_autoload_register().<commit_msg>[2.0] Some cleanup for previous commit.<commit_after><?php

namespace Doctrine\Common;

/**
 * A class loader used to load class files on demand.
 *
 * Usage recommendation:
 * 1) Use only 1 class loader instance.
 * 2) Set the base paths to your class libraries (including Doctrine's) through
 *    $classLoader->setBasePath($prefix, $basePath);
 *    Example:
 *      $classLoader->setBasePath('Doctrine', '/usr/local/phplibs/doctrine/lib');
 *    Then, when trying to load the class Doctrine\ORM\EntityManager, for example
 *    the classloader will look for /usr/local/phplibs/doctrine/lib/Doctrine/ORM/EntityManager.php
 *
 * 3) DO NOT setCheckFileExists(true). Doing so is expensive in terms of performance.
 * 4) Use an opcode-cache (i.e. APC) (STRONGLY RECOMMENDED).
 * 
 * @since 2.0
 * @author romanb <<EMAIL>>
 */
class ClassLoader
{    
    private $_namespaceSeparator = '\\';
    private $_fileExtension = '.php';
    private $_checkFileExists = false;
    private $_basePaths = array();
    
    public function __construct()
    {
    }
    
    public function setCheckFileExists($bool)
    {
        $this->_checkFileExists = $bool;
    }
    
    public function setClassFileExtension($extension)
    {
        $this->_fileExtension = $extension;
    }
    
    public function setNamespaceSeparator($separator)
    {
        $this->_namespaceSeparator = $separator;
    }
    
    /**
     * Sets a static base path for classes with a certain prefix that is prepended
     * to the path derived from the class itself.
     *
     * @param string $basePath
     */
    public function setBasePath($classPrefix, $basePath)
    {
        $this->_basePaths[$classPrefix] = $basePath;
    }
    
    /**
     * Loads the given class or interface.
     *
     * @param string $classname The name of the class to load.
     * @return boolean TRUE if the class has been successfully loaded, FALSE otherwise.
     */
    public function loadClass($className)
    {
        if (class_exists($className, false) || interface_exists($className, false)) {
            return false;
        }

        $prefix = substr($className, 0, strpos($className, $this->_namespaceSeparator));
        $class = '';
        if (isset($this->_basePaths[$prefix])) {
            $class .= $this->_basePaths[$prefix] . DIRECTORY_SEPARATOR;
        }

        $class .= str_replace(array($this->_namespaceSeparator, '_'), DIRECTORY_SEPARATOR, $className)
                . $this->_fileExtension;

        if ($this->_checkFileExists) {
            if (!$fh = @fopen($class, 'r', true)) {
                return false;
            }
            @fclose($fh);
        }

        require $class;
        
        return true;
    }
    
    /**
     * Registers this class loader using spl_autoload_register().
{'fraction_non_alphanumeric': 0.11936900308993333, 'fraction_numerical': 0.0032525613920962758, 'mean_word_length': 2.306451612903226, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 33, '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': '955613', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1727, 'n_words': 471}