diff --git a/phpmyfaq/404.php b/phpmyfaq/404.php
index 12d22a0c37..87684f1b92 100644
--- a/phpmyfaq/404.php
+++ b/phpmyfaq/404.php
@@ -16,9 +16,7 @@
*/
use phpMyFAQ\Enums\SessionActionType;
-use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
-use phpMyFAQ\User\CurrentUser;
if (!defined('IS_VALID_PHPMYFAQ')) {
http_response_code(400);
@@ -26,10 +24,10 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
-$faqSession->setCurrentUser($user);
+$user = $container->get('phpmyfaq.user.current_user');
+$faqSession = $container->get('phpmyfaq.session');
+$faqSession->setCurrentUser($user);
$faqSession->userTracking(SessionActionType::NOT_FOUND->value, 0);
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
diff --git a/phpmyfaq/add.php b/phpmyfaq/add.php
index 7e468b1e23..1724c5e4b6 100644
--- a/phpmyfaq/add.php
+++ b/phpmyfaq/add.php
@@ -15,21 +15,16 @@
* @since 2002-09-16
*/
-use phpMyFAQ\Captcha\Captcha;
-use phpMyFAQ\Captcha\Helper\CaptchaHelper;
-use phpMyFAQ\Category;
use phpMyFAQ\Enums\Forms\FormIds;
use phpMyFAQ\Enums\PermissionType;
use phpMyFAQ\Filter;
use phpMyFAQ\Forms;
use phpMyFAQ\Helper\CategoryHelper as HelperCategory;
use phpMyFAQ\Question;
-use phpMyFAQ\Session;
use phpMyFAQ\Strings;
use phpMyFAQ\System;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -42,8 +37,9 @@
$faqSystem = new System();
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
+$user = $container->get('phpmyfaq.user.current_user');
+
+$faqSession = $container->get('phpmyfaq.session');
$faqSession->setCurrentUser($user);
// Check user permissions
@@ -58,7 +54,7 @@
$response->send();
}
-$captcha = Captcha::getInstance($faqConfig);
+$captcha = $container->get('phpmyfaq.captcha');
$captcha->setSessionId($sids);
$questionObject = new Question($faqConfig);
@@ -86,12 +82,12 @@
$categoryHelper = new HelperCategory();
$categoryHelper->setCategory($category);
-$captchaHelper = CaptchaHelper::getInstance($faqConfig);
+$captchaHelper = $container->get('phpmyfaq.captcha.helper.captcha_helper');
$forms = new Forms($faqConfig);
$formData = $forms->getFormData(FormIds::ADD_NEW_FAQ->value);
-$category = new Category($faqConfig);
+$category = new $container->get('phpmyfaq.category');
$categories = $category->getAllCategoryIds();
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
diff --git a/phpmyfaq/ask.php b/phpmyfaq/ask.php
index 09368bae50..1685d18210 100644
--- a/phpmyfaq/ask.php
+++ b/phpmyfaq/ask.php
@@ -15,16 +15,12 @@
* @since 2002-09-17
*/
-use phpMyFAQ\Captcha\Captcha;
-use phpMyFAQ\Captcha\Helper\CaptchaHelper;
use phpMyFAQ\Enums\Forms\FormIds;
use phpMyFAQ\Filter;
use phpMyFAQ\Forms;
use phpMyFAQ\Helper\CategoryHelper as HelperCategory;
-use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -33,9 +29,12 @@
exit();
}
+$request = Request::createFromGlobals();
+
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
+$user = $container->get('phpmyfaq.user.current_user');
+
+$faqSession = $container->get('phpmyfaq.session');
$faqSession->setCurrentUser($user);
// Check user permissions
@@ -44,8 +43,7 @@
$response->send();
}
-$request = Request::createFromGlobals();
-$captcha = Captcha::getInstance($faqConfig);
+$captcha = $container->get('phpmyfaq.captcha');
$captcha->setSessionId($sids);
$faqSession->userTracking('ask_question', 0);
@@ -57,7 +55,7 @@
$categoryHelper = new HelperCategory();
$categoryHelper->setCategory($category);
-$captchaHelper = CaptchaHelper::getInstance($faqConfig);
+$captchaHelper = $container->get('phpmyfaq.captcha.helper.captcha_helper');
$forms = new Forms($faqConfig);
$formData = $forms->getFormData(FormIds::ASK_QUESTION->value);
diff --git a/phpmyfaq/attachment.php b/phpmyfaq/attachment.php
index c61691f16c..3163505658 100644
--- a/phpmyfaq/attachment.php
+++ b/phpmyfaq/attachment.php
@@ -22,7 +22,6 @@
use phpMyFAQ\Permission\MediumPermission;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
use Symfony\Component\HttpFoundation\Request;
if (!defined('IS_VALID_PHPMYFAQ')) {
@@ -42,7 +41,7 @@
$request = Request::createFromGlobals();
// authenticate with session information
-$user = CurrentUser::getCurrentUser($faqConfig);
+$user = $container->get('phpmyfaq.user.current_user');
$id = Filter::filterVar($request->query->get('id'), FILTER_VALIDATE_INT);
diff --git a/phpmyfaq/bookmarks.php b/phpmyfaq/bookmarks.php
index 874d422549..949ce8b905 100644
--- a/phpmyfaq/bookmarks.php
+++ b/phpmyfaq/bookmarks.php
@@ -19,7 +19,6 @@
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Bookmark;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
use phpMyFAQ\Session\Token;
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -29,7 +28,7 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
+$user = $container->get('phpmyfaq.user.current_user');
if ($user->isLoggedIn()) {
$bookmark = new Bookmark($faqConfig, $user);
diff --git a/phpmyfaq/contact.php b/phpmyfaq/contact.php
index 979db5461c..1a21a7734d 100644
--- a/phpmyfaq/contact.php
+++ b/phpmyfaq/contact.php
@@ -15,12 +15,8 @@
* @since 2002-09-16
*/
-use phpMyFAQ\Captcha\Captcha;
-use phpMyFAQ\Captcha\Helper\CaptchaHelper;
-use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
if (!defined('IS_VALID_PHPMYFAQ')) {
http_response_code(400);
@@ -29,16 +25,16 @@
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
-$faqSession->setCurrentUser($user);
+$user = $container->get('phpmyfaq.user.current_user');
+$faqSession = $container->get('phpmyfaq.session');
+$faqSession->setCurrentUser($user);
$faqSession->userTracking('contact', 0);
-$captcha = Captcha::getInstance($faqConfig);
+$captcha = $container->get('phpmyfaq.captcha');
$captcha->setSessionId($sids);
-$captchaHelper = CaptchaHelper::getInstance($faqConfig);
+$captchaHelper = $container->get('phpmyfaq.captcha.helper.captcha_helper');
if ($faqConfig->get('layout.contactInformationHTML')) {
$contactText = html_entity_decode((string) $faqConfig->get('main.contactInformation'));
diff --git a/phpmyfaq/faq.php b/phpmyfaq/faq.php
index ad0f4868a2..f419045687 100644
--- a/phpmyfaq/faq.php
+++ b/phpmyfaq/faq.php
@@ -19,8 +19,6 @@
use League\CommonMark\CommonMarkConverter;
use phpMyFAQ\Attachment\AttachmentException;
use phpMyFAQ\Attachment\AttachmentFactory;
-use phpMyFAQ\Bookmark;
-use phpMyFAQ\Captcha\Captcha;
use phpMyFAQ\Captcha\Helper\CaptchaHelper;
use phpMyFAQ\Comments;
use phpMyFAQ\Date;
@@ -41,7 +39,6 @@
use phpMyFAQ\Search\SearchResultSet;
use phpMyFAQ\Seo;
use phpMyFAQ\Services;
-use phpMyFAQ\Session;
use phpMyFAQ\Session\Token;
use phpMyFAQ\Strings;
use phpMyFAQ\Tags;
@@ -59,7 +56,7 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
+$user = $container->get('phpmyfaq.user.current_user');
$glossary = new Glossary($faqConfig);
$tagging = new Tags($faqConfig);
@@ -70,7 +67,8 @@
$faqPermission = new Permission($faqConfig);
$seo = new Seo($faqConfig);
$attachmentHelper = new AttachmentHelper();
-$faqSession = new Session($faqConfig);
+
+$faqSession = $container->get('phpmyfaq.session');
$faqSession->setCurrentUser($user);
$converter = new CommonMarkConverter([
@@ -88,7 +86,7 @@
$faqSearchResult = new SearchResultSet($user, $faqPermission, $faqConfig);
-$captcha = Captcha::getInstance($faqConfig);
+$captcha = $container->get('phpmyfaq.captcha');
$captcha->setSessionId($sids);
$currentCategory = $cat;
@@ -100,7 +98,7 @@
$bookmarkAction = Filter::filterVar($request->query->get('bookmark_action'), FILTER_SANITIZE_SPECIAL_CHARS);
// Handle bookmarks
-$bookmark = new Bookmark($faqConfig, $user);
+$bookmark = $container->get('phpmyfaq.bookmark');
if ($bookmarkAction === 'add' && isset($faqId)) {
$bookmark->add($faqId);
}
diff --git a/phpmyfaq/glossary.php b/phpmyfaq/glossary.php
index 72d519ee38..262679a13f 100644
--- a/phpmyfaq/glossary.php
+++ b/phpmyfaq/glossary.php
@@ -18,10 +18,8 @@
use phpMyFAQ\Filter;
use phpMyFAQ\Glossary;
use phpMyFAQ\Pagination;
-use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
use Symfony\Component\HttpFoundation\Request;
if (!defined('IS_VALID_PHPMYFAQ')) {
@@ -30,10 +28,10 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
-$faqSession->setCurrentUser($user);
+$user = $container->get('phpmyfaq.user.current_user');
+$faqSession = $container->get('phpmyfaq.session');
+$faqSession->setCurrentUser($user);
$faqSession->userTracking('glossary', 0);
$request = Request::createFromGlobals();
diff --git a/phpmyfaq/index.php b/phpmyfaq/index.php
index 87dcd49e18..2e96254358 100755
--- a/phpmyfaq/index.php
+++ b/phpmyfaq/index.php
@@ -23,7 +23,6 @@
use phpMyFAQ\Attachment\AttachmentFactory;
use phpMyFAQ\Category;
use phpMyFAQ\Category\Relation;
-use phpMyFAQ\Configuration;
use phpMyFAQ\Core\Exception;
use phpMyFAQ\Entity\SeoEntity;
use phpMyFAQ\Enums\PermissionType;
diff --git a/phpmyfaq/login.php b/phpmyfaq/login.php
index 4b319cdb98..78cf1586b4 100644
--- a/phpmyfaq/login.php
+++ b/phpmyfaq/login.php
@@ -15,10 +15,8 @@
* @since 2012-02-12
*/
-use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
if (!defined('IS_VALID_PHPMYFAQ')) {
http_response_code(400);
@@ -26,9 +24,11 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
+$user = $container->get('phpmyfaq.user.current_user');
+
+$faqSession = $container->get('phpmyfaq.session');
$faqSession->setCurrentUser($user);
+$faqSession->userTracking('login', 0);
$loginMessage = '';
@@ -36,7 +36,6 @@
$loginMessage = '
' . $error . '
';
}
-$faqSession->userTracking('login', 0);
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twigTemplate = $twig->loadTemplate('./login.twig');
diff --git a/phpmyfaq/news.php b/phpmyfaq/news.php
index 6a35de86f5..604223bb4c 100644
--- a/phpmyfaq/news.php
+++ b/phpmyfaq/news.php
@@ -17,7 +17,6 @@
* @since 2006-07-23
*/
-use phpMyFAQ\Captcha\Captcha;
use phpMyFAQ\Captcha\Helper\CaptchaHelper;
use phpMyFAQ\Comments;
use phpMyFAQ\Date;
@@ -28,12 +27,10 @@
use phpMyFAQ\Helper\CommentHelper;
use phpMyFAQ\Helper\FaqHelper;
use phpMyFAQ\News;
-use phpMyFAQ\Session;
use phpMyFAQ\Session\Token;
use phpMyFAQ\Strings;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
use Symfony\Component\HttpFoundation\Request;
if (!defined('IS_VALID_PHPMYFAQ')) {
@@ -42,11 +39,12 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
+$user = $container->get('phpmyfaq.user.current_user');
+
+$faqSession = $container->get('phpmyfaq.session');
$faqSession->setCurrentUser($user);
-$captcha = Captcha::getInstance($faqConfig);
+$captcha = $container->get('phpmyfaq.captcha');
$captcha->setSessionId($sids);
$comment = new Comments($faqConfig);
diff --git a/phpmyfaq/open-questions.php b/phpmyfaq/open-questions.php
index d6c23e14ab..c715100d03 100644
--- a/phpmyfaq/open-questions.php
+++ b/phpmyfaq/open-questions.php
@@ -15,12 +15,9 @@
* @since 2002-09-17
*/
-use phpMyFAQ\Category;
use phpMyFAQ\Helper\QuestionHelper;
-use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
if (!defined('IS_VALID_PHPMYFAQ')) {
http_response_code(400);
@@ -28,13 +25,13 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
+$user = $container->get('phpmyfaq.user.current_user');
-$faqSession = new Session($faqConfig);
+$faqSession = $container->get('phpmyfaq.session');
$faqSession->setCurrentUser($user);
$faqSession->userTracking('open_questions', 0);
-$category = new Category($faqConfig);
+$category = new $container->get('phpmyfaq.category');
$questionHelper = new QuestionHelper();
$questionHelper
->setConfiguration($faqConfig)
diff --git a/phpmyfaq/overview.php b/phpmyfaq/overview.php
index 48ca038871..fa6db7282c 100644
--- a/phpmyfaq/overview.php
+++ b/phpmyfaq/overview.php
@@ -16,13 +16,11 @@
*/
use phpMyFAQ\Helper\FaqHelper;
-use phpMyFAQ\Session;
use phpMyFAQ\Template\CategoryNameTwigExtension;
use phpMyFAQ\Template\CreateLinkTwigExtension;
use phpMyFAQ\Template\FaqTwigExtension;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
if (!defined('IS_VALID_PHPMYFAQ')) {
http_response_code(400);
@@ -30,10 +28,10 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
-$faqSession->setCurrentUser($user);
+$user = $container->get('phpmyfaq.user.current_user');
+$faqSession = $container->get('phpmyfaq.session');
+$faqSession->setCurrentUser($user);
$faqSession->userTracking('overview', 0);
$faqHelper = new FaqHelper($faqConfig);
diff --git a/phpmyfaq/password.php b/phpmyfaq/password.php
index 43a3425099..31a5b9c2f4 100644
--- a/phpmyfaq/password.php
+++ b/phpmyfaq/password.php
@@ -15,7 +15,6 @@
* @since 2012-03-26
*/
-use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
if (!defined('IS_VALID_PHPMYFAQ')) {
@@ -24,8 +23,8 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$faqSession = new Session($faqConfig);
+$faqSession = $container->get('phpmyfaq.session');
$faqSession->userTracking('forgot_password', 0);
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
diff --git a/phpmyfaq/pdf.php b/phpmyfaq/pdf.php
index 3dfe4142b9..6ca349ee8c 100644
--- a/phpmyfaq/pdf.php
+++ b/phpmyfaq/pdf.php
@@ -78,7 +78,7 @@
Strings::init($faqLangCode);
// authenticate with session information
-$user = CurrentUser::getCurrentUser($faqConfig);
+$user = $container->get('phpmyfaq.user.current_user');
// Get current user and group id - default: -1
[ $currentUser, $currentGroups ] = CurrentUser::getCurrentUserGroupId($user);
diff --git a/phpmyfaq/register.php b/phpmyfaq/register.php
index 6eb82f9bcc..50163364c0 100644
--- a/phpmyfaq/register.php
+++ b/phpmyfaq/register.php
@@ -16,12 +16,8 @@
* @since 2008-01-25
*/
-use phpMyFAQ\Captcha\Captcha;
-use phpMyFAQ\Captcha\Helper\CaptchaHelper;
-use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -32,21 +28,21 @@
$request = Request::createFromGlobals();
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
-$faqSession->setCurrentUser($user);
+$user = $container->get('phpmyfaq.user.current_user');
if (!$faqConfig->get('security.enableRegistration')) {
$redirect = new RedirectResponse($faqConfig->getDefaultUrl());
$redirect->send();
}
+$faqSession = $container->get('phpmyfaq.session');
+$faqSession->setCurrentUser($user);
$faqSession->userTracking('registration', 0);
-$captcha = Captcha::getInstance($faqConfig);
+$captcha = $container->get('phpmyfaq.captcha');
$captcha->setSessionId($sids);
-$captchaHelper = CaptchaHelper::getInstance($faqConfig);
+$captchaHelper = $container->get('phpmyfaq.captcha.helper.captcha_helper');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twigTemplate = $twig->loadTemplate('./register.twig');
diff --git a/phpmyfaq/request-removal.php b/phpmyfaq/request-removal.php
index ee1d4f7603..144cb43858 100644
--- a/phpmyfaq/request-removal.php
+++ b/phpmyfaq/request-removal.php
@@ -15,10 +15,8 @@
* @since 2018-02-03
*/
-use phpMyFAQ\Session;
use phpMyFAQ\Session\Token;
use phpMyFAQ\Template\TwigWrapper;
-use phpMyFAQ\User\CurrentUser;
if (!defined('IS_VALID_PHPMYFAQ')) {
http_response_code(400);
@@ -26,10 +24,10 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
-$faqSession->setCurrentUser($user);
+$user = $container->get('phpmyfaq.user.current_user');
+$faqSession = $container->get('phpmyfaq.session');
+$faqSession->setCurrentUser($user);
$faqSession->userTracking('request_removal', 0);
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
diff --git a/phpmyfaq/search.php b/phpmyfaq/search.php
index 3dab460d00..9e86462fc1 100755
--- a/phpmyfaq/search.php
+++ b/phpmyfaq/search.php
@@ -15,7 +15,6 @@
* @since 2002-09-16
*/
-use phpMyFAQ\Category;
use phpMyFAQ\Faq;
use phpMyFAQ\Faq\Permission;
use phpMyFAQ\Filter;
@@ -26,13 +25,11 @@
use phpMyFAQ\Pagination;
use phpMyFAQ\Search;
use phpMyFAQ\Search\SearchResultSet;
-use phpMyFAQ\Session;
use phpMyFAQ\Strings;
use phpMyFAQ\Tags;
use phpMyFAQ\Template\TagNameTwigExtension;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -42,10 +39,10 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
-$faqSession->setCurrentUser($user);
+$user = $container->get('phpmyfaq.user.current_user');
+$faqSession = $container->get('phpmyfaq.session');
+$faqSession->setCurrentUser($user);
$faqSession->userTracking('fulltext_search', 0);
$faq = new Faq($faqConfig);
@@ -85,7 +82,7 @@
// for any of the multi-language faq records and the Entity list
// on the left pane will not be affected
if ($allLanguages) {
- $category = new Category($faqConfig);
+ $category = $container->get('phpmyfaq.category');
$category->transform(0);
}
diff --git a/phpmyfaq/show.php b/phpmyfaq/show.php
index 1bb6f0ce76..5d6951810f 100644
--- a/phpmyfaq/show.php
+++ b/phpmyfaq/show.php
@@ -20,10 +20,8 @@
use phpMyFAQ\Helper\CategoryHelper;
use phpMyFAQ\Language\Plurals;
use phpMyFAQ\Link;
-use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -35,8 +33,9 @@
$request = Request::createFromGlobals();
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
+$user = $container->get('phpmyfaq.user.current_user');
+
+$faqSession = $container->get('phpmyfaq.session');
$faqSession->setCurrentUser($user);
$selectedCategoryId = Filter::filterVar($request->query->get('cat'), FILTER_VALIDATE_INT);
diff --git a/phpmyfaq/sitemap.php b/phpmyfaq/sitemap.php
index 70a5604768..e86d46425b 100644
--- a/phpmyfaq/sitemap.php
+++ b/phpmyfaq/sitemap.php
@@ -17,12 +17,9 @@
*/
use phpMyFAQ\Filter;
-use phpMyFAQ\Session;
-use phpMyFAQ\Sitemap;
use phpMyFAQ\Strings;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
use Symfony\Component\HttpFoundation\Request;
if (!defined('IS_VALID_PHPMYFAQ')) {
@@ -31,10 +28,10 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
-$faqSession->setCurrentUser($user);
+$user = $container->get('phpmyfaq.user.current_user');
+$faqSession = $container->get('phpmyfaq.session');
+$faqSession->setCurrentUser($user);
$faqSession->userTracking('sitemap', 0);
$request = Request::createFromGlobals();
@@ -45,7 +42,7 @@
$currLetter = '';
}
-$siteMap = new Sitemap($faqConfig);
+$siteMap = $container->get('phpmyfaq.sitemap');
$siteMap->setUser($currentUser);
$siteMap->setGroups($currentGroups);
diff --git a/phpmyfaq/src/phpMyFAQ/Comments.php b/phpmyfaq/src/phpMyFAQ/Comments.php
index 71f879e984..fca06a7df6 100644
--- a/phpmyfaq/src/phpMyFAQ/Comments.php
+++ b/phpmyfaq/src/phpMyFAQ/Comments.php
@@ -18,9 +18,7 @@
namespace phpMyFAQ;
use DateTimeInterface;
-use Exception;
use phpMyFAQ\Entity\CommentType;
-use phpMyFAQ\Services\Gravatar;
use phpMyFAQ\Entity\Comment;
/**
diff --git a/phpmyfaq/src/phpMyFAQ/Template/TwigWrapper.php b/phpmyfaq/src/phpMyFAQ/Template/TwigWrapper.php
index 608d429fc7..38b64d101f 100644
--- a/phpmyfaq/src/phpMyFAQ/Template/TwigWrapper.php
+++ b/phpmyfaq/src/phpMyFAQ/Template/TwigWrapper.php
@@ -50,7 +50,7 @@ public function __construct(string $templatePath, bool $isSetup = false)
// Always add the translation extension
$this->twigEnvironment->addExtension(new TranslateTwigExtension());
- // Always add the plugin extension
+ // Add the plugin extension if it's not in the setup phase
if (!$isSetup) {
$this->twigEnvironment->addExtension(new PluginTwigExtension());
}
diff --git a/phpmyfaq/src/services.php b/phpmyfaq/src/services.php
index 5c7184be0b..3c844c8ab6 100644
--- a/phpmyfaq/src/services.php
+++ b/phpmyfaq/src/services.php
@@ -15,8 +15,17 @@
* @since 2024-10-07
*/
+use phpMyFAQ\Bookmark;
+use phpMyFAQ\Captcha\Captcha;
+use phpMyFAQ\Captcha\Helper\CaptchaHelper;
+use phpMyFAQ\Category;
use phpMyFAQ\Configuration;
+use phpMyFAQ\Services\Gravatar;
+use phpMyFAQ\Session;
+use phpMyFAQ\Sitemap;
+use phpMyFAQ\User\CurrentUser;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
+use Symfony\Component\DependencyInjection\Reference;
return static function (ContainerConfigurator $container): void {
// Parameters
@@ -25,6 +34,47 @@
// Services
$services = $container->services();
+ $services->set('phpmyfaq.bookmark', Bookmark::class)
+ ->args([
+ new Reference('phpmyfaq.configuration'),
+ new Reference('phpmyfaq.user.current_user')
+ ]);
+
+ $services->set('phpmyfaq.captcha', Captcha::class)
+ ->factory([Captcha::class, 'getInstance'])
+ ->args([
+ new Reference('phpmyfaq.configuration')
+ ]);
+
+ $services->set('phpmyfaq.captcha.helper.captcha_helper', CaptchaHelper::class)
+ ->factory([CaptchaHelper::class, 'getInstance'])
+ ->args([
+ new Reference('phpmyfaq.configuration')
+ ]);
+
+ $services->set('phpmyfaq.category', Category::class)
+ ->args([
+ new Reference('phpmyfaq.configuration')
+ ]);
+
$services->set('phpmyfaq.configuration', Configuration::class)
->factory([Configuration::class, 'getConfigurationInstance']);
+
+ $services->set('phpmyfaq.session', Session::class)
+ ->args([
+ new Reference('phpmyfaq.configuration')
+ ]);
+
+ $services->set('phpmyfaq.sitemap', Sitemap::class)
+ ->args([
+ new Reference('phpmyfaq.configuration')
+ ]);
+
+ $services->set('phpmyfaq.services.gravatar', Gravatar::class);
+
+ $services->set('phpmyfaq.user.current_user', CurrentUser::class)
+ ->factory([CurrentUser::class, 'getCurrentUser'])
+ ->args([
+ new Reference('phpmyfaq.configuration')
+ ]);
};
diff --git a/phpmyfaq/ucp.php b/phpmyfaq/ucp.php
index 32a9aa7b5c..46d724658e 100644
--- a/phpmyfaq/ucp.php
+++ b/phpmyfaq/ucp.php
@@ -15,13 +15,10 @@
* @since 2012-01-12
*/
-use phpMyFAQ\Services\Gravatar;
-use phpMyFAQ\Session;
use phpMyFAQ\Session\Token;
use phpMyFAQ\Strings;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
-use phpMyFAQ\User\CurrentUser;
use phpMyFAQ\User\TwoFactor;
use RobThree\Auth\TwoFactorAuthException;
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -32,15 +29,15 @@
}
$faqConfig = $container->get('phpmyfaq.configuration');
-$user = CurrentUser::getCurrentUser($faqConfig);
-$faqSession = new Session($faqConfig);
-$faqSession->setCurrentUser($user);
+$user = $container->get('phpmyfaq.user.current_user');
if ($user->isLoggedIn()) {
+ $faqSession = $container->get('phpmyfaq.session');
+ $faqSession->setCurrentUser($user);
$faqSession->userTracking('user_control_panel', $user->getUserId());
if ($faqConfig->get('main.enableGravatarSupport')) {
- $gravatar = new Gravatar();
+ $gravatar = $container->get('phpmyfaq.services.gravatar');
$gravatarImg = sprintf(
'%s',
$gravatar->getImage(
@@ -65,9 +62,7 @@
$twoFactor->saveSecret($secret);
}
$qrCode = $twoFactor->getQrCode($secret);
- } catch (TwoFactorAuthException $e) {
- // handle exception
- } catch (\phpMyFAQ\Core\Exception $e) {
+ } catch (TwoFactorAuthException | Exception $e) {
// handle exception
}