1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 
<?php
namespace Omeka\Db;

use Doctrine\Common\Proxy\Autoloader;

class ProxyAutoloader
{
    public static function register($proxyDirs, $proxyNamespace)
    {
        $proxyNamespace = ltrim($proxyNamespace, '\\');

        $autoloader = function ($className) use ($proxyDirs, $proxyNamespace) {
            if (0 === strpos($className, $proxyNamespace)) {
                foreach ($proxyDirs as $proxyDir) {
                    $file = Autoloader::resolveFile($proxyDir, $proxyNamespace, $className);

                    if (file_exists($file)) {
                        require $file;
                        break;
                    }
                }
            }
        };

        spl_autoload_register($autoloader);
        return $autoloader;
    }
}