Sha256: 39f2ebdf9138cca0933c8c677474bae5807717b140e78846583929df76e6e938

Contents?: true

Size: 847 Bytes

Versions: 7

Compression:

Stored size: 847 Bytes

Contents

<?php

namespace Predis;

class Autoloader {
    private $base_directory;
    private $prefix;

    public function __construct($base_directory=NULL) {
        $this->base_directory = $base_directory ?: dirname(__FILE__);
        $this->prefix = __NAMESPACE__ . '\\';
    }

    public static function register() {
        spl_autoload_register(array(new self, 'autoload'));
    }

    public function autoload($class_name) {
        if (0 !== strpos($class_name, $this->prefix)) {
            return;
        }

        $relative_class_name = substr($class_name, strlen($this->prefix));
        $class_name_parts = explode('\\', $relative_class_name);

        $path = $this->base_directory .
            DIRECTORY_SEPARATOR .
            implode(DIRECTORY_SEPARATOR, $class_name_parts) .
            '.php';

        require_once $path;
    }
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
appstats-0.25.1 doc/benchmarks/Predis/Autoloader.php
appstats-0.25.0 doc/benchmarks/Predis/Autoloader.php
appstats-0.24.0 doc/benchmarks/Predis/Autoloader.php
appstats-0.23.5 doc/benchmarks/Predis/Autoloader.php
appstats-0.23.4 doc/benchmarks/Predis/Autoloader.php
appstats-0.23.3 doc/benchmarks/Predis/Autoloader.php
appstats-0.23.2 doc/benchmarks/Predis/Autoloader.php