move Thelia namespace into core/lib directory

introduce prod / dev environment
This commit is contained in:
Manuel Raynaud
2012-10-03 11:24:46 +02:00
parent 4682d484fd
commit e4fcadd3ec
7 changed files with 180 additions and 2 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace Thelia\Autoload;
class TheliaApcUniversalClassLoader extends TheliaUniversalClassLoader {
private $prefix;
/**
* Constructor
*
* Come from Symfony\Component\ClassLoader\ApcUniversalClassLoader
*
* @param string $prefix
* @throws \RuntimeException
*/
public function __construct($prefix) {
if (!extension_loaded('apc')) {
throw new \RuntimeException('Unable to use ApcUniversalClassLoader as APC is not enabled.');
}
$this->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;
}
}
?>

View File

@@ -0,0 +1,82 @@
<?php
namespace Thelia\Autoload;
use Symfony\Component\ClassLoader\UniversalClassLoader;
/**
* TheliaUniversalClassLoader
*
* extends Symfony\Component\ClassLoader\UniversalClassLoader
*
* This class respect PSR-0 autoloading standard and allow to load traditionnal Thelia classes
*
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*
*/
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);
}
}
?>

View File

@@ -0,0 +1,10 @@
<?php
namespace Thelia;
class Thelia {
}
?>