<commit_before><?php
namespace Agl\Core;

use \Agl\Core\Data\String as StringData,
    \Exception;

/**
 * Load class on demand.
 *
 * @category Agl_Core
 * @package Agl_Core
 * @version 0.1.0
 */

class Autoload
{
    /**
     * The AGL pool is used to detect if a class should be loaded from AGL.
     */
    const AGL_POOL = 'Agl';

    /**
     * Class aliases. Allow the use of a short class name instead of the full
     * name with namespace.
     *
     * @var array
     */
    private static $_aliases = array(
        'Agl'        => '\Agl\Core\Agl',
        'Arr'        => '\Agl\Core\Data\Arr',
        'Block'      => '\Agl\Core\Mvc\Block\Block',
        'Collection' => '\Agl\Core\Db\Collection\Collection',
        'Conditions' => '\Agl\Core\Db\Query\Conditions\Conditions',
        'Controller' => '\Agl\Core\Mvc\Controller\Controller',
        'Date'       => '\Agl\Core\Data\Date',
        'Debug'      => '\Agl\Core\Debug\Debug',
        'Dir'        => '\Agl\Core\Data\Dir',
        'File'       => '\Agl\Core\Data\File',
        'Model'      => '\Agl\Core\Mvc\Model\Model',
        'Observer'   => '\Agl\Core\Observer\Observer',
        'Registry'   => '\Agl\Core\Registry\Registry',
        'Select'     => '\Agl\Core\Db\Query\Select\Select',
        'String'     => '\Agl\Core\Data\String',
        'Url'        => '\Agl\Core\Url\Url',
        'Validation' => '\Agl\Core\Data\Validation',
        'View'       => '\Agl\Core\Mvc\View\View'
    );

    /**
     * Register the autoload methods.
     *
     * @return Autoload
     */
    public function __construct()
    {
        spl_autoload_register(array($this, '_load'));
    }

    /**
     * Load class file if exists.
     *
     * @param sting $pClassName Class name
     */
    private function _load($pClassName)
    {
        if (array_key_exists($pClassName, self::$_aliases)) {
            return class_alias(self::$_aliases[$pClassName], $pClassName);
        }

        if (strpos($pClassName, self::AGL_POOL) === 0) {
            $path     = self::_loadFromAgl($pClassName);
            $realPath = AGL_PATH . $path . Agl::PHP_EXT;
        } else {
            $realPath = self::_loadFromApp($pClassName);
        }

        if ($realPath and is_readable($realPath)) {
            require($realPath);
        } else {
            throw new Exception("'$pClassName' not found, real path empty");
        }
    }

    /**
     * Retrieve the class path in the AGL pool.
     *
     * @param string $pClassName Class name
     * @return string Class path
     */
    private static function _loadFromAgl($pClassName)
    {
        return str_replace(array(
            self::AGL_POOL . '\\' . Agl::AGL_CORE_DIR . '\\',
            '\\'
        ), array(
            '',
            '/'
        ), $pClassName);
    }

    /**
     * Retrieve the class path in the application pool.
     *
     * @param string $pClassName Class name
     * @return string Class path
     */
    private static function _loadFromApp($pClassName)
    {
        $classNameArr = explode('_', StringData::fromCamelCase($pClassName));
        $pool         = array_pop($classNameArr);

        return APP_PATH
               . Agl::APP_PHP_DIR
               . $pool
               . DS
               . implode(DS, $classNameArr)
               . Agl::PHP_EXT;
    }
}
<commit_msg>Do not thow exception if autoloading failed (allow to process spl_autoload_register queue if any).<commit_after><?php
namespace Agl\Core;

use \Agl\Core\Data\String as StringData,
    \Exception;

/**
 * Load class on demand.
 *
 * @category Agl_Core
 * @package Agl_Core
 * @version 0.1.0
 */

class Autoload
{
    /**
     * The AGL pool is used to detect if a class should be loaded from AGL.
     */
    const AGL_POOL = 'Agl';

    /**
     * Class aliases. Allow the use of a short class name instead of the full
     * name with namespace.
     *
     * @var array
     */
    private static $_aliases = array(
        'Agl'        => '\Agl\Core\Agl',
        'Arr'        => '\Agl\Core\Data\Arr',
        'Block'      => '\Agl\Core\Mvc\Block\Block',
        'Collection' => '\Agl\Core\Db\Collection\Collection',
        'Conditions' => '\Agl\Core\Db\Query\Conditions\Conditions',
        'Controller' => '\Agl\Core\Mvc\Controller\Controller',
        'Date'       => '\Agl\Core\Data\Date',
        'Debug'      => '\Agl\Core\Debug\Debug',
        'Dir'        => '\Agl\Core\Data\Dir',
        'File'       => '\Agl\Core\Data\File',
        'Model'      => '\Agl\Core\Mvc\Model\Model',
        'Observer'   => '\Agl\Core\Observer\Observer',
        'Registry'   => '\Agl\Core\Registry\Registry',
        'Select'     => '\Agl\Core\Db\Query\Select\Select',
        'String'     => '\Agl\Core\Data\String',
        'Url'        => '\Agl\Core\Url\Url',
        'Validation' => '\Agl\Core\Data\Validation',
        'View'       => '\Agl\Core\Mvc\View\View'
    );

    /**
     * Register the autoload methods.
     *
     * @return Autoload
     */
    public function __construct()
    {
        spl_autoload_register(array($this, '_load'));
    }

    /**
     * Load class file if exists.
     *
     * @param sting $pClassName Class name
     */
    private function _load($pClassName)
    {
        if (array_key_exists($pClassName, self::$_aliases)) {
            return class_alias(self::$_aliases[$pClassName], $pClassName);
        }

        if (strpos($pClassName, self::AGL_POOL) === 0) {
            $path     = self::_loadFromAgl($pClassName);
            $realPath = AGL_PATH . $path . Agl::PHP_EXT;
        } else {
            $realPath = self::_loadFromApp($pClassName);
        }

        if ($realPath and is_readable($realPath)) {
            require($realPath);
        }
    }

    /**
     * Retrieve the class path in the AGL pool.
     *
     * @param string $pClassName Class name
     * @return string Class path
     */
    private static function _loadFromAgl($pClassName)
    {
        return str_replace(array(
            self::AGL_POOL . '\\' . Agl::AGL_CORE_DIR . '\\',
            '\\'
        ), array(
            '',
            '/'
        ), $pClassName);
    }

    /**
     * Retrieve the class path in the application pool.
     *
     * @param string $pClassName Class name
     * @return string Class path
     */
    private static function _loadFromApp($pClassName)
    {
        $classNameArr = explode('_', StringData::fromCamelCase($pClassName));
        $pool         = array_pop($classNameArr);

        return APP_PATH
               . Agl::APP_PHP_DIR
               . $pool
               . DS
               . implode(DS, $classNameArr)
               . Agl::PHP_EXT;
    }
}

{'fraction_non_alphanumeric': 0.1466407302109831, 'fraction_numerical': 0.0011970671853957803, 'mean_word_length': 1.7619834710743802, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '2612240', 'n_tokens_mistral': 2114, 'n_tokens_neox': 2103, 'n_words': 434}