diff --git a/core/autoload.php b/core/autoload.php index fe69751f5..68817a993 100644 --- a/core/autoload.php +++ b/core/autoload.php @@ -1,6 +1,31 @@ $directory) { + $loader->registerNamespace($namespace, $directory); +} + +$loader->register('Thelia',__DIR__ . '/lib/'); + + +$loader->register(); + -return $loader; ?> diff --git a/core/bootstrap.php b/core/bootstrap.php index b50dbad8f..20a539efe 100644 --- a/core/bootstrap.php +++ b/core/bootstrap.php @@ -1,6 +1,21 @@ diff --git a/core/lib/Thelia/Autoload/TheliaApcUniversalClassLoader.php b/core/lib/Thelia/Autoload/TheliaApcUniversalClassLoader.php new file mode 100644 index 000000000..8549b646d --- /dev/null +++ b/core/lib/Thelia/Autoload/TheliaApcUniversalClassLoader.php @@ -0,0 +1,43 @@ +prefix = $prefix; + } + + + /** + * Finds a file by class name while caching lookups to APC. + * + * Come from Symfony\Component\ClassLoader\ApcUneiversalClassLoader + * + * @param string $class A class name to resolve to file + * + * @return string|null The path, if found + */ + public function findFile($class) { + if (false === $file = apc_fetch($this->prefix.$class)) { + apc_store($this->prefix.$class, $file = parent::findFile($class)); + } + + return $file; + } +} +?> diff --git a/core/lib/Thelia/Autoload/TheliaUniversalClassLoader.php b/core/lib/Thelia/Autoload/TheliaUniversalClassLoader.php new file mode 100644 index 000000000..d7fffc667 --- /dev/null +++ b/core/lib/Thelia/Autoload/TheliaUniversalClassLoader.php @@ -0,0 +1,82 @@ + + * + */ + +class TheliaUniversalClassLoader extends UniversalClassLoader{ + + private $directories = array(); + + /** + * + * add path directory where autoload can search files + * + * @param string $directory + */ + public function addDirectory($directory){ + $this->directories[] = $directory; + } + + + /** + * + * add multiple path directory in an array where autoload can search files + * + * @param array $directories + */ + public function addDirectories(array $directories){ + foreach($directories as $directory){ + $this->addDirectory($directory); + } + } + + /** + * + * return directories where traditional Thelia classes can be found + * + * @return array an Array of directories + */ + public function getDirectories(){ + return $this->directories; + } + + /** + * + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * @return string|null The path, if found + */ + public function findFile($class) { + + foreach($this->directories as $directory){ + + if(is_file($directory.DIRECTORY_SEPARATOR.$class.".class.php")){ + return $directory.DIRECTORY_SEPARATOR.$class.".class.php"; + } + + if(is_file($directory.DIRECTORY_SEPARATOR.$class.".interface.php")){ + return $directory.DIRECTORY_SEPARATOR.$class.".interface.php"; + } + + } + + return parent::findFile($class); + } + +} + + +?> diff --git a/core/Thelia/Thelia.php b/core/lib/Thelia/Thelia.php similarity index 100% rename from core/Thelia/Thelia.php rename to core/lib/Thelia/Thelia.php diff --git a/index.php b/index.php index 62a2de0c8..f35abc7bd 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,8 @@ diff --git a/index_dev.php b/index_dev.php new file mode 100644 index 000000000..caf2630f7 --- /dev/null +++ b/index_dev.php @@ -0,0 +1,8 @@ +