Files
Phraseanet/lib/Alchemy/Phrasea/Loader/Autoloader.php
Romain Neutron 8a154e21c1 Coding Standards
2012-02-13 18:23:06 +01:00

96 lines
2.0 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Loader;
require_once __DIR__ . "/../../../vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php";
use Symfony\Component\ClassLoader\UniversalClassLoader;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Autoloader extends UniversalClassLoader
{
/**
* An array of path to check
* @var type
*/
private $paths = array();
/**
* Construct a new phrasea Autoloader
* Because some custom classes from library folder might be
* overwritten in config folder
* Phraseanet Loader look classes in configuration folders first
* then check library folder if no classes where matched
*/
public function __construct()
{
$this->paths['config'] = __DIR__ . '/../../../../config/classes/';
$this->paths['library'] = __DIR__ . '/../../../classes/';
}
/**
* {@inheritdoc}
*/
public function findFile($class)
{
if (!$file = $this->checkFile($class))
{
$file = parent::findFile($class);
}
return $file;
}
/**
* Add a path to look for autoloading phraseanet classes
* @param string $name
* @param string $path
*/
public function addPath($name, $path)
{
$this->paths[$name] = \p4string::addEndSlash($path);
}
/**
* Check whether a class with $class name exists
* foreach declared paths
* @param string $class
* @return mixed string|null
*/
private function checkFile($class)
{
foreach($this->paths as $path)
{
$file = $path. str_replace('_', '/', $class) . '.class.php';
if(file_exists($file))
{
return $file;
}
}
}
/**
* Get Paths where classes are checked for autoloading
* @return Array
*/
public function getPaths()
{
return $this->paths;
}
}