diff --git a/main/admin/user_list.php b/main/admin/user_list.php index b3d2442ce0..3c788cbe48 100644 --- a/main/admin/user_list.php +++ b/main/admin/user_list.php @@ -5,7 +5,8 @@ @author Julio Montoya BeezNest 2011 * @package chamilo.admin */ -use ChamiloSession as Session; +use Chamilo\CoreBundle\Framework\Container; + // name of the language file that needs to be included $language_file = array ('registration','admin'); $cidReset = true; @@ -410,7 +411,7 @@ function modify_filter($user_id, $url_params, $row) { ) ) { if (!$user_is_anonymous) { - if (Session::getSecurity()->isGranted('ROLE_GLOBAL_ADMIN')) { + if (Container::getSecurity()->isGranted('ROLE_GLOBAL_ADMIN')) { // everything looks good, show "login as" link if ($user_id != $userId) { $result .= ''.Display::return_icon('login_as.gif', get_lang('LoginAs')).'  '; diff --git a/main/calendar/agenda_js.php b/main/calendar/agenda_js.php index 265e8b1e74..f48e15990e 100644 --- a/main/calendar/agenda_js.php +++ b/main/calendar/agenda_js.php @@ -4,7 +4,7 @@ * @package chamilo.calendar */ -use \ChamiloSession as Session; +use Chamilo\CoreBundle\Framework\Container; // use anonymous mode when accessing this course tool $use_anonymous = true; @@ -60,7 +60,7 @@ if (!empty($group_id)) { } $app['title'] = get_lang('Agenda'); -$tpl = Session::getTwig(); +$tpl = Container::getTwig(); $tpl->addGlobal('use_google_calendar', 0); $can_add_events = 0; diff --git a/main/inc/ajax/exercise.ajax.php b/main/inc/ajax/exercise.ajax.php index caf38d4bb4..85b99ab909 100644 --- a/main/inc/ajax/exercise.ajax.php +++ b/main/inc/ajax/exercise.ajax.php @@ -9,6 +9,7 @@ require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php'; require_once api_get_path(SYS_CODE_PATH).'exercice/answer.class.php'; use \ChamiloSession as Session; +use Chamilo\CoreBundle\Framework\Container; api_protect_course_script(true); diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index 4f87f003e9..4ea03b8e60 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -12,6 +12,7 @@ use \ChamiloSession as Session; use Symfony\Component\Validator\Constraints as Assert; use Application\Sonata\UserBundle\Entity\User; use Chamilo\CoreBundle\Entity\Course; +use Chamilo\CoreBundle\Framework\Container; /** * Constants declaration @@ -617,8 +618,8 @@ function api_get_path($path_type, $path = null) { // Default $_configuration['root_web'] configuration //$root_web = isset($_configuration['root_web']) ? $_configuration['root_web'] : $app['url_generator']; - $root_web = Session::getUrlGenerator()->generate('home'); //$_configuration['root_web']; - $rootDir = Session::getRootDir(); + $root_web = Container::getUrlGenerator()->generate('home'); //$_configuration['root_web']; + $rootDir = Container::getRootDir(); // Configuration data for already installed system. $root_sys = $rootDir; @@ -659,10 +660,10 @@ function api_get_path($path_type, $path = null) { $paths[SYS_PATH] = $root_sys; // Update data path to get it from config file if defined - $paths[SYS_DATA_PATH] = Session::getDataDir(); - $paths[SYS_LOG_PATH] = Session::getLogDir(); - $paths[SYS_CONFIG_PATH] = Session::getConfigDir(); - $paths[SYS_COURSE_PATH] = Session::getCourseDir(); + $paths[SYS_DATA_PATH] = Container::getDataDir(); + $paths[SYS_LOG_PATH] = Container::getLogDir(); + $paths[SYS_CONFIG_PATH] = Container::getConfigDir(); + $paths[SYS_COURSE_PATH] = Container::getCourseDir(); $paths[SYS_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[SYS_DATA_PATH].'default_course_document/'; @@ -689,7 +690,7 @@ function api_get_path($path_type, $path = null) { // Now we can switch into api_get_path() "terminology". $paths[SYS_LANG_PATH] = $paths[SYS_CODE_PATH].$paths[SYS_LANG_PATH]; $paths[SYS_PLUGIN_PATH] = $paths[SYS_PATH].$paths[SYS_PLUGIN_PATH]; - $paths[SYS_ARCHIVE_PATH] = Session::getTempDir(); + $paths[SYS_ARCHIVE_PATH] = Container::getTempDir(); $paths[SYS_TEST_PATH] = $paths[SYS_PATH].$paths[SYS_TEST_PATH]; $paths[SYS_TEMPLATE_PATH] = $paths[SYS_CODE_PATH].$paths[SYS_TEMPLATE_PATH]; $paths[SYS_CSS_PATH] = $paths[SYS_PATH].$paths[SYS_CSS_PATH]; @@ -2198,7 +2199,7 @@ function api_get_self() { */ function api_is_platform_admin($allow_sessions_admins = false) { - $security = Session::getSecurity(); + $security = Container::getSecurity(); if ($security) { $token = $security->getToken(); @@ -2221,7 +2222,7 @@ function api_is_platform_admin($allow_sessions_admins = false) */ function api_is_question_manager() { - $security = Session::getSecurity(); + $security = Container::getSecurity(); $token = $security->getToken(); if (!empty($token)) { if ($security->isGranted('ROLE_QUESTION_MANAGER')) { @@ -2238,7 +2239,7 @@ function api_is_question_manager() */ function api_is_session_admin() { - $security = Session::getSecurity(); + $security = Container::getSecurity(); $token = $security->getToken(); if (!empty($token)) { if ($security->isGranted('ROLE_SESSION_MANAGER')) { @@ -2253,7 +2254,7 @@ function api_is_session_admin() * @return boolean True if current user is a human resources manager */ function api_is_drh() { - $security = Session::getSecurity(); + $security = Container::getSecurity(); $token = $security->getToken(); if (!empty($token)) { if ($security->isGranted('ROLE_RRHH')) { @@ -2268,7 +2269,7 @@ function api_is_drh() { * @return boolean True if current user is a human resources manager */ function api_is_student() { - $security = Session::getSecurity(); + $security = Container::getSecurity(); $token = $security->getToken(); if (!empty($token)) { if ($security->isGranted('ROLE_STUDENT')) { @@ -2283,7 +2284,7 @@ function api_is_student() { * @return boolean True if current user is a human resources manager */ function api_is_teacher() { - $security = Session::getSecurity(); + $security = Container::getSecurity(); $token = $security->getToken(); if (!empty($token)) { if ($security->isGranted('ROLE_TEACHER')) { diff --git a/main/inc/lib/chamilo_session.class.php b/main/inc/lib/chamilo_session.class.php index df4c83f2e8..d126f71199 100644 --- a/main/inc/lib/chamilo_session.class.php +++ b/main/inc/lib/chamilo_session.class.php @@ -1,138 +1,12 @@ get($variable); + if (isset($session)) { + $result = $session->get($variable); } // Check if the value exists in the $_SESSION array if (empty($result)) { @@ -158,9 +33,10 @@ class ChamiloSession */ public static function write($variable, $value) { + $session = Container::getSession(); // Writing the session in 2 instances because $_SESSION[$variable] = $value; - self::$session->set($variable, $value); + $session->set($variable, $value); } /** @@ -169,7 +45,8 @@ class ChamiloSession public static function erase($variable) { $variable = (string) $variable; - self::$session->remove($variable); + $session = Container::getSession(); + $session->remove($variable); if (isset($GLOBALS[$variable])) { unset($GLOBALS[$variable]); @@ -180,18 +57,20 @@ class ChamiloSession } /** - * + * Clear session */ public static function clear() { - self::$session->clear(); + $session = Container::getSession(); + $session->clear(); } /** - * + * Invalidates a session */ public static function destroy() { - self::$session->invalidate(); + $session = Container::getSession(); + $session->invalidate(); } } diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 8f07e99792..c33b6d577b 100644 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -2,6 +2,7 @@ /* For licensing terms, see /license.txt */ use ChamiloSession as Session; +use Chamilo\CoreBundle\Framework\Container; /** * Class Display @@ -816,7 +817,7 @@ class Display $icon = 'bundles/chamilocore/img/'.$icon; - $icon = Session::getAsset()->getUrl($icon); + $icon = Container::getAsset()->getUrl($icon); //$icon = api_get_cdn_path($icon); if ($return_only_path) { return $icon; diff --git a/main/inc/lib/formvalidator/Element/html_editor.php b/main/inc/lib/formvalidator/Element/html_editor.php index f1af89bbf4..5407814c41 100644 --- a/main/inc/lib/formvalidator/Element/html_editor.php +++ b/main/inc/lib/formvalidator/Element/html_editor.php @@ -1,5 +1,6 @@ editor = $editor; $this->editor->setName($name); diff --git a/main/inc/lib/internationalization.lib.php b/main/inc/lib/internationalization.lib.php index 725277cb10..ecc70e8928 100644 --- a/main/inc/lib/internationalization.lib.php +++ b/main/inc/lib/internationalization.lib.php @@ -11,6 +11,7 @@ * @package chamilo.library */ use \ChamiloSession as Session; +use Chamilo\CoreBundle\Framework\Container; use Symfony\Component\Intl\DateFormatter\IntlDateFormatter; // Predefined date formats in Chamilo provided by the language sub-system. @@ -50,11 +51,11 @@ define('PERSON_NAME_DATA_EXPORT', PERSON_NAME_EASTERN_ORDER); // Contextual: for function get_lang($variable) { $defaultDomain = 'all'; - $translated = Session::getTranslator()->trans($variable, array(), $defaultDomain); + $translated = Container::getTranslator()->trans($variable, array(), $defaultDomain); if ($translated == $variable) { // Check the langVariable for BC - $translated = Session::getTranslator()->trans("lang$variable", array(), $defaultDomain); + $translated = Container::getTranslator()->trans("lang$variable", array(), $defaultDomain); if ($translated == "lang$variable") { return $variable; } @@ -123,7 +124,7 @@ function api_purify_language_id($language) */ function api_get_language_isocode($language = null, $default_code = 'en') { - return Session::getTranslator()->getLocale(); + return Container::getTranslator()->getLocale(); static $iso_code = array(); if (empty($language)) { diff --git a/src/Chamilo/CoreBundle/Controller/LegacyController.php b/src/Chamilo/CoreBundle/Controller/LegacyController.php index 46ee6135da..d72e962e17 100644 --- a/src/Chamilo/CoreBundle/Controller/LegacyController.php +++ b/src/Chamilo/CoreBundle/Controller/LegacyController.php @@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use \ChamiloSession as Session; +use Chamilo\CoreBundle\Framework\Container; use Display; /** @@ -42,21 +43,21 @@ class LegacyController extends BaseController $fileToLoad = $mainPath.$name; // Legacy inclusions - Session::setSession($this->getRequest()->getSession()); + Container::setSession($request->getSession()); $dbConnection = $this->container->get('database_connection'); $database = new \Database($dbConnection, array()); - Session::$urlGenerator = $this->container->get('router'); - Session::$security = $this->container->get('security.context'); - Session::$translator = $this->container->get('translator'); - Session::$assets = $this->container->get('templating.helper.assets'); - Session::$rootDir = $this->container->get('kernel')->getRealRootDir(); - Session::$logDir = $this->container->get('kernel')->getLogDir(); - Session::$dataDir = $this->container->get('kernel')->getDataDir(); - Session::$tempDir = $this->container->get('kernel')->getCacheDir(); - Session::$courseDir = $this->container->get('kernel')->getDataDir(); - //Session::$configDir = $this->container->get('kernel')->getConfigDir(); - Session::$htmlEditor = $this->container->get('html_editor'); - Session::$twig = $this->container->get('twig'); + Container::$urlGenerator = $this->container->get('router'); + Container::$security = $this->container->get('security.context'); + Container::$translator = $this->container->get('translator'); + Container::$assets = $this->container->get('templating.helper.assets'); + Container::$rootDir = $this->container->get('kernel')->getRealRootDir(); + Container::$logDir = $this->container->get('kernel')->getLogDir(); + Container::$dataDir = $this->container->get('kernel')->getDataDir(); + Container::$tempDir = $this->container->get('kernel')->getCacheDir(); + Container::$courseDir = $this->container->get('kernel')->getDataDir(); + //Container::$configDir = $this->container->get('kernel')->getConfigDir(); + Container::$htmlEditor = $this->container->get('html_editor'); + Container::$twig = $this->container->get('twig'); if (is_file($fileToLoad) && \Security::check_abs_path($fileToLoad, $mainPath) diff --git a/src/Chamilo/CoreBundle/EventListener/LegacyListener.php b/src/Chamilo/CoreBundle/EventListener/LegacyListener.php index ab553c60ca..628ff76af3 100644 --- a/src/Chamilo/CoreBundle/EventListener/LegacyListener.php +++ b/src/Chamilo/CoreBundle/EventListener/LegacyListener.php @@ -5,11 +5,10 @@ namespace Chamilo\CoreBundle\EventListener; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Event\FilterControllerEvent; -use \ChamiloSession as Session; +use Chamilo\CoreBundle\Framework\Container; class LegacyListener { @@ -33,24 +32,31 @@ class LegacyListener $session = $request->getSession(); $container = $this->container; - // Loading legacy variables - Session::setSession($request->getSession()); - $dbConnection = $this->container->get('database_connection'); - $database = new \Database($dbConnection, array()); + // Setting session. + Container::setSession($request->getSession()); + + // Setting database. + $dbConnection = $container->get('database_connection'); - \Database::setManager($this->container->get('doctrine')->getManager()); - \CourseManager::setToolList($this->container->get('chamilo.tool_chain')); - Session::$urlGenerator = $this->container->get('router'); - Session::$security = $this->container->get('security.context'); - Session::$translator = $this->container->get('translator'); - Session::$rootDir = $this->container->get('kernel')->getRealRootDir(); - Session::$logDir = $this->container->get('kernel')->getLogDir(); - Session::$dataDir = $this->container->get('kernel')->getDataDir(); - Session::$tempDir = $this->container->get('kernel')->getCacheDir(); - Session::$courseDir = $this->container->get('kernel')->getDataDir(); - //Session::$configDir = $this->container->get('kernel')->getConfigDir(); - Session::$assets = $this->container->get('templating.helper.assets'); - Session::$htmlEditor = $this->container->get('html_editor'); + // Setting db manager. + $database = new \Database($dbConnection, array()); + \Database::setManager($container->get('doctrine')->getManager()); + + // Setting course tool chain. + \CourseManager::setToolList($container->get('chamilo.tool_chain')); + + // Setting legacy properties + Container::$urlGenerator = $container->get('router'); + Container::$security = $container->get('security.context'); + Container::$translator = $container->get('translator'); + Container::$rootDir = $container->get('kernel')->getRealRootDir(); + Container::$logDir = $container->get('kernel')->getLogDir(); + Container::$dataDir = $container->get('kernel')->getDataDir(); + Container::$tempDir = $container->get('kernel')->getCacheDir(); + Container::$courseDir = $container->get('kernel')->getDataDir(); + //Container::$configDir = $container->get('kernel')->getConfigDir(); + Container::$assets = $container->get('templating.helper.assets'); + Container::$htmlEditor = $container->get('html_editor'); if (!defined('DEFAULT_DOCUMENT_QUOTA')) { $default_quota = api_get_setting('default_document_quotum'); @@ -72,13 +78,13 @@ class LegacyListener $courseCode = $courseCodeFromRequest; } /** @var \Doctrine\ORM\EntityManager $em */ - $em = $this->container->get('doctrine')->getManager(); + $em = $container->get('doctrine')->getManager(); if (!empty($courseCode)) { $course = $em->getRepository('ChamiloCoreBundle:Course')->findOneByCode($courseCode); if ($course) { $courseInfo = api_get_course_info($course->getCode()); - $this->container->get('twig')->addGlobal('course', $course); + $container->get('twig')->addGlobal('course', $course); $request->getSession()->set('_real_cid', $course->getId()); $request->getSession()->set('_cid', $course->getCode()); $request->getSession()->set('_course', $courseInfo); diff --git a/src/Chamilo/CoreBundle/Framework/Application.php b/src/Chamilo/CoreBundle/Framework/Application.php deleted file mode 100644 index ba646c6d87..0000000000 --- a/src/Chamilo/CoreBundle/Framework/Application.php +++ /dev/null @@ -1,173 +0,0 @@ -installed; - } - - /** - * @param array $paths - */ - public function bindInstallPaths(array $paths) - { - foreach ($paths as $key => $value) { - $this['path.'.$key] = realpath($value).'/'; - } - } - - /** - * @return array - */ - public function getConfigurationArray() - { - return $this->configurationArray; - } - - /** - * @return Config - */ - public function getConfiguration() - { - return $this->configuration; - } - - /** - * @return bool|mixed - */ - public function getConfigurationArrayFromFile() - { - $configurationFile = $this['path.config'].'configuration.php'; - if (file_exists($configurationFile)) { - return require_once $configurationFile; - } - - return array(); - } - - /** - * Reads the configuration.php file - */ - public function readConfigurationFiles() - { - $this->configuration = $this->getConfigurationArrayFromFile(); - - if (!empty($this->configuration)) { - $config = new Config($this->configuration, true); - $this->installed = true; - - /** Overwriting paths if set */ - - $this['path.data'] = empty($config->get('path.data')) ? $this['path.data'] : $config->get('path.data'); - $this['path.course'] = empty($config->get('path.courses')) ? $this['path.courses'] : $config->get('path.courses'); - $this['path.temp'] = empty($config->get('path.temp')) ? $this['path.temp'] : $config->get('path.temp'); - $this['path.logs'] = empty($config->get('path.logs')) ? $this['path.logs'] : $config->get('path.logs'); - - $configPath = $this['path.config']; - - $confFiles = array( - 'auth.conf.php', - 'events.conf.php', - 'mail.conf.php', - 'portfolio.conf.php', - 'profile.conf.php' - ); - - foreach ($confFiles as $confFile) { - if (file_exists($configPath . $confFile)) { - require_once $configPath . $confFile; - } - } - - // Fixing $_configuration array - - // Fixes bug in Chamilo 1.8.7.1 array was not set - /*$administrator['email'] = isset($administrator['email']) ? $administrator['email'] : 'admin@example.com'; - $administrator['name'] = isset($administrator['name']) ? $administrator['name'] : 'Admin';*/ - - // Code for transitional purposes, it can be removed right before the 1.8.7 release. - /*if (empty($_configuration['system_version'])) { - $_configuration['system_version'] = (!empty($_configuration['dokeos_version']) ? $_configuration['dokeos_version'] : ''); - $_configuration['system_stable'] = (!empty($_configuration['dokeos_stable']) ? $_configuration['dokeos_stable'] : ''); - $_configuration['software_url'] = 'http://www.chamilo.org/'; - }*/ - - // For backward compatibility. - //$this->configuration['dokeos_version'] = isset($this->configuration['system_version']) ? $this->configuration['system_version'] : null; - //$_configuration['dokeos_stable'] = $_configuration['system_stable']; - //$userPasswordCrypted = (!empty($_configuration['password_encryption']) ? $_configuration['password_encryption'] : 'sha1'); - //$this->configuration['password_encryption'] = isset($this->configuration['password_encryption']) ? $this->configuration['password_encryption'] : 'sha1'; - $this->configurationArray = $this->configuration; - $this->configuration = $config; - } - } - - public function setupDoctrineExtensions() - { - if (isset($this->getConfiguration()->main_database) && isset($this['db.event_manager'])) { - - // @todo improvement do not create every time this objects - $sortableGroup = new \Gedmo\Mapping\Annotation\SortableGroup(array()); - $sortablePosition = new \Gedmo\Mapping\Annotation\SortablePosition(array()); - $tree = new \Gedmo\Mapping\Annotation\Tree(array()); - $tree = new \Gedmo\Mapping\Annotation\TreeParent(array()); - $tree = new \Gedmo\Mapping\Annotation\TreeLeft(array()); - $tree = new \Gedmo\Mapping\Annotation\TreeRight(array()); - $tree = new \Gedmo\Mapping\Annotation\TreeRoot(array()); - $tree = new \Gedmo\Mapping\Annotation\TreeLevel(array()); - $tree = new \Gedmo\Mapping\Annotation\Versioned(array()); - $tree = new \Gedmo\Mapping\Annotation\Loggable(array()); - $tree = new \Gedmo\Loggable\Entity\LogEntry(); - - // Setting Doctrine2 extensions - $timestampableListener = new \Gedmo\Timestampable\TimestampableListener(); - // $app['db.event_manager']->addEventSubscriber($timestampableListener); - $this['dbs.event_manager']['db_read']->addEventSubscriber($timestampableListener); - $this['dbs.event_manager']['db_write']->addEventSubscriber($timestampableListener); - - $sluggableListener = new \Gedmo\Sluggable\SluggableListener(); - // $this['db.event_manager']->addEventSubscriber($sluggableListener); - $this['dbs.event_manager']['db_read']->addEventSubscriber($sluggableListener); - $this['dbs.event_manager']['db_write']->addEventSubscriber($sluggableListener); - - $sortableListener = new \Gedmo\Sortable\SortableListener(); - // $this['db.event_manager']->addEventSubscriber($sortableListener); - $this['dbs.event_manager']['db_read']->addEventSubscriber($sortableListener); - $this['dbs.event_manager']['db_write']->addEventSubscriber($sortableListener); - - $treeListener = new \Gedmo\Tree\TreeListener(); - //$treeListener->setAnnotationReader($cachedAnnotationReader); - // $this['db.event_manager']->addEventSubscriber($treeListener); - $this['dbs.event_manager']['db_read']->addEventSubscriber($treeListener); - $this['dbs.event_manager']['db_write']->addEventSubscriber($treeListener); - - $loggableListener = new \Gedmo\Loggable\LoggableListener(); - if (PHP_SAPI != 'cli') { - //$userInfo = api_get_user_info(); - if (isset($userInfo) && !empty($userInfo['username'])) { - //$loggableListener->setUsername($userInfo['username']); - } - } - $this['dbs.event_manager']['db_read']->addEventSubscriber($loggableListener); - $this['dbs.event_manager']['db_write']->addEventSubscriber($loggableListener); - } - - } -} diff --git a/src/Chamilo/CoreBundle/Framework/Container.php b/src/Chamilo/CoreBundle/Framework/Container.php new file mode 100644 index 0000000000..7ab380a143 --- /dev/null +++ b/src/Chamilo/CoreBundle/Framework/Container.php @@ -0,0 +1,145 @@ +