Skip to content

Commit

Permalink
feat: added Symfony DependencyInjection for Configuration class
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Oct 7, 2024
1 parent fb9a5d0 commit b0ebc59
Show file tree
Hide file tree
Showing 24 changed files with 67 additions and 46 deletions.
3 changes: 1 addition & 2 deletions phpmyfaq/404.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* @since 2019-01-25
*/

use phpMyFAQ\Configuration;
use phpMyFAQ\Enums\SessionActionType;
use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
Expand All @@ -26,7 +25,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use phpMyFAQ\Captcha\Captcha;
use phpMyFAQ\Captcha\Helper\CaptchaHelper;
use phpMyFAQ\Category;
use phpMyFAQ\Configuration;
use phpMyFAQ\Enums\Forms\FormIds;
use phpMyFAQ\Enums\PermissionType;
use phpMyFAQ\Filter;
Expand All @@ -42,7 +41,7 @@
$request = Request::createFromGlobals();
$faqSystem = new System();

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/ask.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use phpMyFAQ\Captcha\Captcha;
use phpMyFAQ\Captcha\Helper\CaptchaHelper;
use phpMyFAQ\Configuration;
use phpMyFAQ\Enums\Forms\FormIds;
use phpMyFAQ\Filter;
use phpMyFAQ\Forms;
Expand All @@ -34,7 +33,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use phpMyFAQ\Attachment\AttachmentException;
use phpMyFAQ\Attachment\AttachmentFactory;
use phpMyFAQ\Configuration;
use phpMyFAQ\Faq\Permission;
use phpMyFAQ\Filter;
use phpMyFAQ\Permission\MediumPermission;
Expand All @@ -39,7 +38,7 @@

$attachmentErrors = [];

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$request = Request::createFromGlobals();

// authenticate with session information
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/bookmarks.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* @since 2023-07-20
*/

use phpMyFAQ\Configuration;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Bookmark;
use phpMyFAQ\Translation;
Expand All @@ -29,7 +28,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);

if ($user->isLoggedIn()) {
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use phpMyFAQ\Captcha\Captcha;
use phpMyFAQ\Captcha\Helper\CaptchaHelper;
use phpMyFAQ\Configuration;
use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
Expand All @@ -29,7 +28,7 @@
}


$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use phpMyFAQ\Captcha\Captcha;
use phpMyFAQ\Captcha\Helper\CaptchaHelper;
use phpMyFAQ\Comments;
use phpMyFAQ\Configuration;
use phpMyFAQ\Date;
use phpMyFAQ\Entity\CommentType;
use phpMyFAQ\Entity\SeoEntity;
Expand Down Expand Up @@ -59,7 +58,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);

$glossary = new Glossary($faqConfig);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/glossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* @since 2012-09-03
*/

use phpMyFAQ\Configuration;
use phpMyFAQ\Filter;
use phpMyFAQ\Glossary;
use phpMyFAQ\Pagination;
Expand All @@ -30,7 +29,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
16 changes: 15 additions & 1 deletion phpmyfaq/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
use phpMyFAQ\User\CurrentUser;
use phpMyFAQ\User\TwoFactor;
use phpMyFAQ\User\UserAuthentication;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -66,7 +69,18 @@
$response = new Response();
$response->headers->set('Content-Type', 'text/html');

$faqConfig = Configuration::getConfigurationInstance();
//
// Service Containers
//
$container = new ContainerBuilder();
$loader = new PhpFileLoader($container, new FileLocator(__DIR__));
try {
$loader->load('src/services.php');
} catch (\Exception $e) {
echo $e->getMessage();
}

$faqConfig = $container->get('phpmyfaq.configuration');

//
// Get language (default: english)
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* @since 2012-02-12
*/

use phpMyFAQ\Configuration;
use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
Expand All @@ -26,7 +25,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use phpMyFAQ\Captcha\Captcha;
use phpMyFAQ\Captcha\Helper\CaptchaHelper;
use phpMyFAQ\Comments;
use phpMyFAQ\Configuration;
use phpMyFAQ\Date;
use phpMyFAQ\Entity\CommentType;
use phpMyFAQ\Enums\PermissionType;
Expand All @@ -42,7 +41,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/open-questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

use phpMyFAQ\Category;
use phpMyFAQ\Configuration;
use phpMyFAQ\Helper\QuestionHelper;
use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
Expand All @@ -28,7 +27,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);

$faqSession = new Session($faqConfig);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* @since 2015-09-27
*/

use phpMyFAQ\Configuration;
use phpMyFAQ\Helper\FaqHelper;
use phpMyFAQ\Session;
use phpMyFAQ\Template\CategoryNameTwigExtension;
Expand All @@ -30,7 +29,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/password.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* @since 2012-03-26
*/

use phpMyFAQ\Configuration;
use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;

Expand All @@ -24,7 +23,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$faqSession = new Session($faqConfig);

$faqSession->userTracking('forgot_password', 0);
Expand Down
4 changes: 1 addition & 3 deletions phpmyfaq/privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@
* @since 2023-01-22
*/

use phpMyFAQ\Configuration;
use Symfony\Component\HttpFoundation\RedirectResponse;

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

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');

$privacyUrl = $faqConfig->get('main.privacyURL');

$redirectUrl = strlen((string) $privacyUrl) > 0 ? $privacyUrl : $faqConfig->get('main.referenceURL');

$response = new RedirectResponse($redirectUrl);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use phpMyFAQ\Captcha\Captcha;
use phpMyFAQ\Captcha\Helper\CaptchaHelper;
use phpMyFAQ\Configuration;
use phpMyFAQ\Session;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
Expand All @@ -32,7 +31,7 @@
}

$request = Request::createFromGlobals();
$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/request-removal.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* @since 2018-02-03
*/

use phpMyFAQ\Configuration;
use phpMyFAQ\Session;
use phpMyFAQ\Session\Token;
use phpMyFAQ\Template\TwigWrapper;
Expand All @@ -26,7 +25,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

use phpMyFAQ\Category;
use phpMyFAQ\Configuration;
use phpMyFAQ\Faq;
use phpMyFAQ\Faq\Permission;
use phpMyFAQ\Filter;
Expand All @@ -42,7 +41,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

use phpMyFAQ\Category;
use phpMyFAQ\Configuration;
use phpMyFAQ\Filter;
use phpMyFAQ\Helper\CategoryHelper;
use phpMyFAQ\Language\Plurals;
Expand All @@ -35,7 +34,7 @@

$request = Request::createFromGlobals();

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* @since 2005-08-21
*/

use phpMyFAQ\Configuration;
use phpMyFAQ\Filter;
use phpMyFAQ\Session;
use phpMyFAQ\Sitemap;
Expand All @@ -31,7 +30,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/sitemap.xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
*/

use phpMyFAQ\Application;
use phpMyFAQ\Configuration;
use phpMyFAQ\Controller\SitemapController;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

require './src/Bootstrap.php';

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');

$routes = new RouteCollection();
$routes->add('public.sitemap.xml', new Route('/sitemap.xml', ['_controller' => [SitemapController::class, 'index']]));
Expand Down
Loading

0 comments on commit b0ebc59

Please sign in to comment.