Moved gatekeeper from core to bootstrap

This commit is contained in:
Nicolas Le Goff
2012-02-03 16:10:32 +01:00
parent 6a437a3831
commit 683fb4cd4e
2 changed files with 39 additions and 40 deletions

View File

@@ -144,12 +144,6 @@ class Core extends \Pimple
!defined('JETON_WRITE_META_SUBDEF') ? define('JETON_WRITE_META_SUBDEF', 0x04) : ''; !defined('JETON_WRITE_META_SUBDEF') ? define('JETON_WRITE_META_SUBDEF', 0x04) : '';
!defined('JETON_WRITE_META') ? define('JETON_WRITE_META', 0x06) : ''; !defined('JETON_WRITE_META') ? define('JETON_WRITE_META', 0x06) : '';
if (\setup::is_installed())
{
$gatekeeper = \gatekeeper::getInstance();
$gatekeeper->check_directory();
}
return; return;
} }
@@ -363,48 +357,47 @@ class Core extends \Pimple
return; return;
} }
/**
* Finds the path to the file where the class is defined.
*
* @param string $class_name the name of the class we are looking for
*/
protected static function phraseaAutoload($class_name)
{
if (file_exists(__DIR__ . '/../../../config/classes/'
. str_replace('_', '/', $class_name) . '.class.php'))
{
require_once __DIR__ . '/../../../config/classes/'
. str_replace('_', '/', $class_name) . '.class.php';
}
elseif (file_exists(__DIR__ . '/../../classes/'
. str_replace('_', '/', $class_name) . '.class.php'))
{
require_once __DIR__ . '/../../classes/'
. str_replace('_', '/', $class_name) . '.class.php';
}
return;
}
/** /**
* Register directory and namespaces for autoloading app classes * Register directory and namespaces for autoloading app classes
* *
*/ */
public static function initAutoloads() public static function initAutoloads($debug = false)
{ {
require_once __DIR__ . '/../../vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php'; require_once __DIR__ . '/../../vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
require_once __DIR__ . '/../../vendor/Twig/lib/Twig/Autoloader.php';
require_once __DIR__ . '/../../vendor/Twig-extensions/lib/Twig/Extensions/Autoloader.php'; require_once __DIR__ . '/Loader/Autoloader.php';
require_once __DIR__ . '/Loader/CacheAutoloader.php';
\Twig_Autoloader::register(); // require_once __DIR__ . '/../../vendor/Twig/lib/Twig/Autoloader.php';
\Twig_Extensions_Autoloader::register(); // require_once __DIR__ . '/../../vendor/Twig-extensions/lib/Twig/Extensions/Autoloader.php';
//
// \Twig_Autoloader::register();
// \Twig_Extensions_Autoloader::register();
$loader = new \Symfony\Component\ClassLoader\UniversalClassLoader();
spl_autoload_register(array('Alchemy\Phrasea\Core', 'phraseaAutoload')); // if ($debug === false)
// {
// try
// {
// $loader = new Loader\CacheAutoloader('class_');
// }
// catch (\Exception $e)
// {
// $loader = new Loader\Autoloader();
// }
// }
// else
// {
$loader = new Loader\Autoloader();
$loader->register();
$loader = new \Symfony\Component\ClassLoader\UniversalClassLoader();
// }
$loader->registerPrefixes(array('Twig_' => realpath(__DIR__ . '/../../vendor/Twig/lib')));
$loader->registerPrefixes(array('Twig_Extensions' => realpath(__DIR__ . '/../../vendor/Twig-extensions/lib')));
$loader->registerNamespaces(array( $loader->registerNamespaces(array(
'Alchemy' => __DIR__ . '/../..', 'Alchemy' => realpath(__DIR__ . '/../..'),
'Symfony' => realpath(__DIR__ . '/../../vendor/symfony/src'), 'Symfony' => realpath(__DIR__ . '/../../vendor/symfony/src'),
'Doctrine\\ORM' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib'), 'Doctrine\\ORM' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib'),
'Doctrine\\DBAL' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib/vendor/doctrine-dbal/lib'), 'Doctrine\\DBAL' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib/vendor/doctrine-dbal/lib'),
@@ -416,7 +409,7 @@ class Core extends \Pimple
'Doctrine\\Logger' => realpath(__DIR__ . '/../../'), 'Doctrine\\Logger' => realpath(__DIR__ . '/../../'),
'Monolog' => realpath(__DIR__ . '/../../vendor/Silex/vendor/monolog/src'), 'Monolog' => realpath(__DIR__ . '/../../vendor/Silex/vendor/monolog/src'),
)); ));
$loader->register(); $loader->register();
require_once __DIR__ . '/../../vendor/Silex/autoload.php'; require_once __DIR__ . '/../../vendor/Silex/autoload.php';

View File

@@ -39,9 +39,15 @@ class bootstrap
{ {
return static::$core; return static::$core;
} }
static::$core = new Core($env); static::$core = new Core($env);
if (\setup::is_installed())
{
$gatekeeper = \gatekeeper::getInstance();
$gatekeeper->check_directory();
}
return static::$core; return static::$core;
} }