Skip to content

Commit

Permalink
feat: added more service containers
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Oct 7, 2024
1 parent b0ebc59 commit ead619f
Show file tree
Hide file tree
Showing 24 changed files with 122 additions and 120 deletions.
8 changes: 3 additions & 5 deletions phpmyfaq/404.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@
*/

use phpMyFAQ\Enums\SessionActionType;
use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\User\CurrentUser;

if (!defined('IS_VALID_PHPMYFAQ')) {
http_response_code(400);
exit();
}

$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());
Expand Down
16 changes: 6 additions & 10 deletions phpmyfaq/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -58,7 +54,7 @@
$response->send();
}

$captcha = Captcha::getInstance($faqConfig);
$captcha = $container->get('phpmyfaq.captcha');
$captcha->setSessionId($sids);

$questionObject = new Question($faqConfig);
Expand Down Expand Up @@ -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());
Expand Down
16 changes: 7 additions & 9 deletions phpmyfaq/ask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/bookmarks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
14 changes: 5 additions & 9 deletions phpmyfaq/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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'));
Expand Down
12 changes: 5 additions & 7 deletions phpmyfaq/faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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([
Expand All @@ -88,7 +86,7 @@

$faqSearchResult = new SearchResultSet($user, $faqPermission, $faqConfig);

$captcha = Captcha::getInstance($faqConfig);
$captcha = $container->get('phpmyfaq.captcha');
$captcha->setSessionId($sids);

$currentCategory = $cat;
Expand All @@ -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);
}
Expand Down
8 changes: 3 additions & 5 deletions phpmyfaq/glossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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();
Expand Down
1 change: 0 additions & 1 deletion phpmyfaq/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions phpmyfaq/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,27 @@
* @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);
exit();
}

$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 = '';

if (!is_null($error)) {
$loginMessage = '<div class="alert alert-danger" role="alert">' . $error . '</div>';
}

$faqSession->userTracking('login', 0);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twigTemplate = $twig->loadTemplate('./login.twig');
Expand Down
10 changes: 4 additions & 6 deletions phpmyfaq/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* @since 2006-07-23
*/

use phpMyFAQ\Captcha\Captcha;
use phpMyFAQ\Captcha\Helper\CaptchaHelper;
use phpMyFAQ\Comments;
use phpMyFAQ\Date;
Expand All @@ -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')) {
Expand All @@ -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);
Expand Down
9 changes: 3 additions & 6 deletions phpmyfaq/open-questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@
* @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);
exit();
}

$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)
Expand Down
Loading

0 comments on commit ead619f

Please sign in to comment.