mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 06:53:15 +00:00
Phrasea Kernel
This commit is contained in:
@@ -18,17 +18,25 @@
|
||||
|
||||
namespace Alchemy\Phrasea;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
require_once __DIR__ . '/../../vendor/Silex/vendor/pimple/lib/Pimple.php';
|
||||
|
||||
class Kernel extends \Pimple
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
public function __construct($isDev = false)
|
||||
{
|
||||
|
||||
/**
|
||||
* Autoload
|
||||
*/
|
||||
$this->bootstrap();
|
||||
static::initAutoloads();
|
||||
|
||||
$this['Version'] = $this->share(function()
|
||||
{
|
||||
return new Kernel\Version();
|
||||
});
|
||||
|
||||
$this['EM'] = $this->share(function()
|
||||
{
|
||||
@@ -36,36 +44,147 @@ class Kernel extends \Pimple
|
||||
return $doctrine->getEntityManager();
|
||||
});
|
||||
|
||||
/**
|
||||
* Gatekeeper
|
||||
*/
|
||||
$this['gatekeeper'] = $this->share(function()
|
||||
{
|
||||
return new \gatekeeper();
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Event Dispatcher
|
||||
*/
|
||||
$this['dispatcher'] = $this->share(function ()
|
||||
$this['Registry'] = $this->share(function()
|
||||
{
|
||||
$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
|
||||
return \registry::get_instance();
|
||||
});
|
||||
|
||||
/**
|
||||
* Initialize Request
|
||||
*/
|
||||
$this['request'] = $this->share(function()
|
||||
$this['Request'] = $this->share(function()
|
||||
{
|
||||
$app['request'] = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
|
||||
return Request::createFromGlobals();
|
||||
});
|
||||
|
||||
self::initPHPConf();
|
||||
|
||||
$this->initLoggers();
|
||||
|
||||
$this->verifyTimeZone();
|
||||
|
||||
\phrasea::start();
|
||||
|
||||
$this->detectLanguage();
|
||||
|
||||
$this->enableLocales();
|
||||
|
||||
$this->enableEvents();
|
||||
|
||||
define('JETON_MAKE_SUBDEF', 0x01);
|
||||
define('JETON_WRITE_META_DOC', 0x02);
|
||||
define('JETON_WRITE_META_SUBDEF', 0x04);
|
||||
define('JETON_WRITE_META', 0x06);
|
||||
|
||||
$gatekeeper = \gatekeeper::getInstance();
|
||||
$gatekeeper->check_directory();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function phraseaAutoload($class_name)
|
||||
/**
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this['Request'];
|
||||
}
|
||||
|
||||
public function getRegistry()
|
||||
{
|
||||
return $this['Registry'];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Alchemy\Phrasea\Kernel\Version
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this['Version'];
|
||||
}
|
||||
|
||||
protected function verifyTimezone()
|
||||
{
|
||||
if ($this->getRegistry()->is_set('GV_timezone'))
|
||||
date_default_timezone_set($this->getRegistry()->get('GV_timezone'));
|
||||
else
|
||||
date_default_timezone_set('Europe/Berlin');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function enableLocales()
|
||||
{
|
||||
mb_internal_encoding("UTF-8");
|
||||
\phrasea::use_i18n($this->getRequest()->getLocale());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function enableEvents()
|
||||
{
|
||||
\phrasea::load_events();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function initLoggers()
|
||||
{
|
||||
$php_log = $this->getRegistry()->get('GV_RootPath') . 'logs/php_error.log';
|
||||
|
||||
ini_set('error_log', $php_log);
|
||||
|
||||
if ($this->getRegistry()->get('GV_debug'))
|
||||
{
|
||||
ini_set('display_errors', 'on');
|
||||
ini_set('display_startup_errors', 'on');
|
||||
}
|
||||
else
|
||||
{
|
||||
ini_set('display_errors', 'off');
|
||||
ini_set('display_startup_errors', 'off');
|
||||
}
|
||||
|
||||
if ($this->getRegistry()->get('GV_log_errors'))
|
||||
{
|
||||
ini_set('log_errors', 'on');
|
||||
}
|
||||
else
|
||||
{
|
||||
ini_set('log_errors', 'off');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function detectLanguage()
|
||||
{
|
||||
$availables = array(
|
||||
'ar_SA' => 'العربية'
|
||||
, 'de_DE' => 'Deutsch'
|
||||
, 'en_GB' => 'English'
|
||||
, 'es_ES' => 'Español'
|
||||
, 'fr_FR' => 'Français'
|
||||
);
|
||||
|
||||
$this->getRequest()->setDefaultLocale(
|
||||
$this->getRegistry()->get('GV_default_lng', 'en_GB')
|
||||
);
|
||||
|
||||
$cookies = $this->getRequest()->cookies;
|
||||
|
||||
if (isset($availables[$cookies->get('locale')]))
|
||||
{
|
||||
$this->getRequest()->setLocale($cookies->get('locale'));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected static function phraseaAutoload($class_name)
|
||||
{
|
||||
if (file_exists(__DIR__ . '/../../../config/classes/'
|
||||
. str_replace('_', '/', $class_name) . '.class.php'))
|
||||
@@ -83,20 +202,48 @@ class Kernel extends \Pimple
|
||||
return;
|
||||
}
|
||||
|
||||
protected function bootstrap()
|
||||
public static function initAutoloads()
|
||||
{
|
||||
require_once __DIR__ . '/../../vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
|
||||
require_once __DIR__ . '/../../vendor/symfony/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';
|
||||
|
||||
$loader = new \Symfony\Component\ClassLoader\UniversalClassLoader();
|
||||
require_once __DIR__ . '/../../vendor/Twig/lib/Twig/Autoloader.php';
|
||||
require_once __DIR__ . '/../../vendor/Twig-extensions/lib/Twig/Extensions/Autoloader.php';
|
||||
|
||||
spl_autoload_register(array($this, 'phraseaAutoload'));
|
||||
\Twig_Autoloader::register();
|
||||
\Twig_Extensions_Autoloader::register();
|
||||
|
||||
$loader = new \Symfony\Component\ClassLoader\ApcUniversalClassLoader('KIKOO');
|
||||
|
||||
spl_autoload_register(array('Alchemy\Phrasea\Kernel', 'phraseaAutoload'));
|
||||
|
||||
$loader->registerNamespaces(array(
|
||||
'Alchemy' => __DIR__ . '/../../',
|
||||
'Symfony\\Component\\Yaml' => __DIR__ . '/../../vendor/symfony/src',
|
||||
'Symfony\\Component\\Console' => __DIR__ . '/../../vendor/symfony/src',
|
||||
));
|
||||
|
||||
$loader->register();
|
||||
|
||||
require_once __DIR__ . '/../../vendor/Silex/autoload.php';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public static function initPHPConf()
|
||||
{
|
||||
ini_set('output_buffering', '4096');
|
||||
if ((int) ini_get('memory_limit') < 2048)
|
||||
ini_set('memory_limit', '2048M');
|
||||
ini_set('error_reporting', '6143');
|
||||
ini_set('default_charset', 'UTF-8');
|
||||
ini_set('session.use_cookies', '1');
|
||||
ini_set('session.use_only_cookies', '1');
|
||||
ini_set('session.auto_start', '0');
|
||||
ini_set('session.hash_function', '1');
|
||||
ini_set('session.hash_bits_per_character', '6');
|
||||
ini_set('allow_url_fopen', 'on');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
36
lib/Alchemy/Phrasea/Kernel/Version.php
Normal file
36
lib/Alchemy/Phrasea/Kernel/Version.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\Kernel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class Version
|
||||
{
|
||||
|
||||
protected static $number = '3.6.0';
|
||||
protected static $name = 'Brachiosaure';
|
||||
|
||||
public static function getNumber()
|
||||
{
|
||||
return static::$number;
|
||||
}
|
||||
|
||||
public static function getName()
|
||||
{
|
||||
return static::$name;
|
||||
}
|
||||
|
||||
}
|
@@ -15,181 +15,38 @@
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../Alchemy/Phrasea/Kernel.php';
|
||||
|
||||
class bootstrap
|
||||
{
|
||||
|
||||
protected static function define_dirs()
|
||||
{
|
||||
$root = dirname(dirname(dirname(__FILE__)));
|
||||
if (!defined('__LIBDIR__'))
|
||||
define('__LIBDIR__', $root . '/lib');
|
||||
if (!defined('__CUSTOMDIR__'))
|
||||
define('__CUSTOMDIR__', $root . '/config');
|
||||
self::require_essentials();
|
||||
}
|
||||
static $kernel;
|
||||
|
||||
public static function set_php_configuration()
|
||||
{
|
||||
ini_set('output_buffering', '4096');
|
||||
if ((int) ini_get('memory_limit') < 2048)
|
||||
ini_set('memory_limit', '2048M');
|
||||
ini_set('error_reporting', '6143');
|
||||
ini_set('default_charset', 'UTF-8');
|
||||
ini_set('session.use_cookies', '1');
|
||||
ini_set('session.use_only_cookies', '1');
|
||||
ini_set('session.auto_start', '0');
|
||||
ini_set('session.hash_function', '1');
|
||||
ini_set('session.hash_bits_per_character', '6');
|
||||
ini_set('allow_url_fopen', 'on');
|
||||
|
||||
return;
|
||||
return Alchemy\Phrasea\Kernel::initPHPConf();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Alchemy\Phrasea\Kernel
|
||||
*/
|
||||
public static function execute()
|
||||
{
|
||||
self::define_dirs();
|
||||
self::require_essentials();
|
||||
|
||||
$registry = registry::get_instance();
|
||||
|
||||
if ($registry->get('GV_RootPath') === false)
|
||||
if(static::$kernel)
|
||||
{
|
||||
$registry->set('GV_RootPath', dirname(__FILE__) . '/../../');
|
||||
$registry->set('GV_debug', true);
|
||||
return static::$kernel;
|
||||
}
|
||||
|
||||
self::set_php_configuration();
|
||||
static::$kernel = new Alchemy\Phrasea\Kernel();
|
||||
|
||||
ini_set('error_log', $registry->get('GV_RootPath') . 'logs/php_error.log');
|
||||
|
||||
if ($registry->get('GV_debug'))
|
||||
{
|
||||
ini_set('display_errors', 'on');
|
||||
ini_set('display_startup_errors', 'on');
|
||||
}
|
||||
else
|
||||
{
|
||||
ini_set('display_errors', 'off');
|
||||
ini_set('display_startup_errors', 'off');
|
||||
}
|
||||
|
||||
if ($registry->get('GV_log_errors'))
|
||||
{
|
||||
ini_set('log_errors', 'on');
|
||||
}
|
||||
else
|
||||
{
|
||||
ini_set('log_errors', 'off');
|
||||
}
|
||||
|
||||
self::register_autoloads();
|
||||
self::init_functions();
|
||||
|
||||
define('JETON_MAKE_SUBDEF', 0x01);
|
||||
define('JETON_WRITE_META_DOC', 0x02);
|
||||
define('JETON_WRITE_META_SUBDEF', 0x04);
|
||||
define('JETON_WRITE_META', 0x06);
|
||||
|
||||
$gatekeeper = gatekeeper::getInstance();
|
||||
$gatekeeper->check_directory();
|
||||
}
|
||||
|
||||
protected static function phrasea_autoload($class_name)
|
||||
{
|
||||
if (file_exists(__CUSTOMDIR__ . '/classes/'
|
||||
. str_replace('_', '/', $class_name) . '.class.php'))
|
||||
{
|
||||
require_once __CUSTOMDIR__ . '/classes/'
|
||||
. str_replace('_', '/', $class_name) . '.class.php';
|
||||
}
|
||||
elseif (file_exists(__LIBDIR__ . '/classes/'
|
||||
. str_replace('_', '/', $class_name) . '.class.php'))
|
||||
{
|
||||
require_once __LIBDIR__ . '/classes/'
|
||||
. str_replace('_', '/', $class_name) . '.class.php';
|
||||
}
|
||||
}
|
||||
|
||||
protected static function require_essentials()
|
||||
{
|
||||
require_once __LIBDIR__ . '/version.inc';
|
||||
require_once __LIBDIR__ . '/classes/cache/opcode/interface.class.php';
|
||||
require_once __LIBDIR__ . '/classes/cache/cacheableInterface.class.php';
|
||||
require_once __LIBDIR__ . '/classes/cache/opcode/adapter.class.php';
|
||||
require_once __LIBDIR__ . '/classes/registryInterface.class.php';
|
||||
require_once __LIBDIR__ . '/classes/registry.class.php';
|
||||
require_once __LIBDIR__ . '/classes/Session/Storage/Interface.class.php';
|
||||
require_once __LIBDIR__ . '/classes/Session/Storage/Abstract.class.php';
|
||||
require_once __LIBDIR__ . '/classes/Session/Storage/PHPSession.class.php';
|
||||
require_once __LIBDIR__ . '/classes/Session/Storage/CommandLine.class.php';
|
||||
require_once __LIBDIR__ . '/classes/base.class.php';
|
||||
require_once __LIBDIR__ . '/classes/appbox.class.php';
|
||||
require_once __LIBDIR__ . '/classes/Session/Handler.class.php';
|
||||
require_once __LIBDIR__ . '/classes/phrasea.class.php';
|
||||
require_once __LIBDIR__ . '/classes/User/Interface.class.php';
|
||||
require_once __LIBDIR__ . '/classes/User/Adapter.class.php';
|
||||
require_once __LIBDIR__ . '/classes/eventsmanager/eventAbstract.class.php';
|
||||
require_once __LIBDIR__ . '/classes/eventsmanager/notifyAbstract.class.php';
|
||||
require_once __LIBDIR__ . '/classes/eventsmanager/broker.class.php';
|
||||
require_once __LIBDIR__ . '/classes/gatekeeper.class.php';
|
||||
require_once __LIBDIR__ . '/classes/http/request.class.php';
|
||||
require_once __LIBDIR__ . '/classes/p4string.class.php';
|
||||
|
||||
require_once __LIBDIR__ . '/classes/connection/interface.class.php';
|
||||
require_once __LIBDIR__ . '/classes/connection/abstract.class.php';
|
||||
require_once __LIBDIR__ . '/classes/connection/pdo.class.php';
|
||||
require_once __LIBDIR__ . '/classes/connection/pdoStatementDebugger.class.php';
|
||||
require_once __LIBDIR__ . '/classes/connection.class.php';
|
||||
return static::$kernel;
|
||||
}
|
||||
|
||||
public static function register_autoloads()
|
||||
{
|
||||
self::define_dirs();
|
||||
|
||||
spl_autoload_register(array('bootstrap', 'phrasea_autoload'));
|
||||
|
||||
require_once __LIBDIR__ . '/vendor/Twig/lib/Twig/Autoloader.php';
|
||||
require_once __LIBDIR__ . '/vendor/Twig-extensions/lib/Twig/Extensions/Autoloader.php';
|
||||
require_once __LIBDIR__ . '/vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
|
||||
|
||||
Twig_Autoloader::register();
|
||||
Twig_Extensions_Autoloader::register();
|
||||
|
||||
/**
|
||||
* Load symfony components needed
|
||||
*/
|
||||
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
|
||||
$loader->registerNamespaces(array(
|
||||
'Symfony\\Component\\Yaml' => __LIBDIR__ . '/vendor/symfony/src',
|
||||
'Symfony\\Component\\Console' => __LIBDIR__ . '/vendor/symfony/src',
|
||||
));
|
||||
$loader->register();
|
||||
|
||||
require_once __LIBDIR__ . '/vendor/Silex/autoload.php';
|
||||
}
|
||||
|
||||
protected static function init_functions()
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
if ($registry->is_set('GV_timezone'))
|
||||
date_default_timezone_set($registry->get('GV_timezone'));
|
||||
else
|
||||
date_default_timezone_set('Europe/Berlin');
|
||||
|
||||
phrasea::start();
|
||||
User_Adapter::detectlanguage($registry);
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
if (Session_Handler::get_cookie('locale') !== Session_Handler::get_locale())
|
||||
{
|
||||
$avLanguages = User_Adapter::detectlanguage($registry, Session_Handler::get_cookie('locale'));
|
||||
}
|
||||
|
||||
mb_internal_encoding("UTF-8");
|
||||
phrasea::use_i18n(Session_Handler::get_locale());
|
||||
phrasea::load_events();
|
||||
return Alchemy\Phrasea\Kernel::initAutoloads();
|
||||
}
|
||||
|
||||
}
|
||||
|
2
lib/classes/cache/opcode/adapter.class.php
vendored
2
lib/classes/cache/opcode/adapter.class.php
vendored
@@ -15,7 +15,7 @@
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class cache_opcode_adapter implements cache_opcode_Interface
|
||||
class cache_opcode_adapter implements cache_opcode_interface
|
||||
{
|
||||
/**
|
||||
*
|
||||
|
@@ -244,10 +244,12 @@ class supertwig
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
}
|
||||
|
||||
$kernel = bootstrap::execute();
|
||||
|
||||
$this->default_vars = array(
|
||||
'session' => $session,
|
||||
'version_number' => GV_version,
|
||||
'version_name' => GV_version_name,
|
||||
'version_number' => $kernel->getVersion()->getNumber(),
|
||||
'version_name' => $kernel->getVersion()->getName(),
|
||||
'browser' => $browser,
|
||||
'request' => $request,
|
||||
'display_chrome_frame' => $registry->is_set('GV_display_gcf') ? $registry->get('GV_display_gcf') : true,
|
||||
|
Reference in New Issue
Block a user