diff --git a/phpmyfaq/404.php b/phpmyfaq/404.php index d5f28623f9..12d22a0c37 100644 --- a/phpmyfaq/404.php +++ b/phpmyfaq/404.php @@ -15,7 +15,6 @@ * @since 2019-01-25 */ -use phpMyFAQ\Configuration; use phpMyFAQ\Enums\SessionActionType; use phpMyFAQ\Session; use phpMyFAQ\Template\TwigWrapper; @@ -26,7 +25,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $faqSession = new Session($faqConfig); $faqSession->setCurrentUser($user); diff --git a/phpmyfaq/add.php b/phpmyfaq/add.php index 702bcccfbb..7e468b1e23 100644 --- a/phpmyfaq/add.php +++ b/phpmyfaq/add.php @@ -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; @@ -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); diff --git a/phpmyfaq/ask.php b/phpmyfaq/ask.php index 746887b0e3..09368bae50 100644 --- a/phpmyfaq/ask.php +++ b/phpmyfaq/ask.php @@ -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; @@ -34,7 +33,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $faqSession = new Session($faqConfig); $faqSession->setCurrentUser($user); diff --git a/phpmyfaq/attachment.php b/phpmyfaq/attachment.php index a582ce0bec..c61691f16c 100644 --- a/phpmyfaq/attachment.php +++ b/phpmyfaq/attachment.php @@ -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; @@ -39,7 +38,7 @@ $attachmentErrors = []; -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $request = Request::createFromGlobals(); // authenticate with session information diff --git a/phpmyfaq/bookmarks.php b/phpmyfaq/bookmarks.php index 86389da019..874d422549 100644 --- a/phpmyfaq/bookmarks.php +++ b/phpmyfaq/bookmarks.php @@ -16,7 +16,6 @@ * @since 2023-07-20 */ -use phpMyFAQ\Configuration; use phpMyFAQ\Template\TwigWrapper; use phpMyFAQ\Bookmark; use phpMyFAQ\Translation; @@ -29,7 +28,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); if ($user->isLoggedIn()) { diff --git a/phpmyfaq/contact.php b/phpmyfaq/contact.php index 9c4482d606..979db5461c 100644 --- a/phpmyfaq/contact.php +++ b/phpmyfaq/contact.php @@ -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; @@ -29,7 +28,7 @@ } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $faqSession = new Session($faqConfig); $faqSession->setCurrentUser($user); diff --git a/phpmyfaq/faq.php b/phpmyfaq/faq.php index db0cede0d7..ad0f4868a2 100644 --- a/phpmyfaq/faq.php +++ b/phpmyfaq/faq.php @@ -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; @@ -59,7 +58,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $glossary = new Glossary($faqConfig); diff --git a/phpmyfaq/glossary.php b/phpmyfaq/glossary.php index 0e103ab0b1..72d519ee38 100644 --- a/phpmyfaq/glossary.php +++ b/phpmyfaq/glossary.php @@ -15,7 +15,6 @@ * @since 2012-09-03 */ -use phpMyFAQ\Configuration; use phpMyFAQ\Filter; use phpMyFAQ\Glossary; use phpMyFAQ\Pagination; @@ -30,7 +29,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $faqSession = new Session($faqConfig); $faqSession->setCurrentUser($user); diff --git a/phpmyfaq/index.php b/phpmyfaq/index.php index cb1e153b9d..87dcd49e18 100755 --- a/phpmyfaq/index.php +++ b/phpmyfaq/index.php @@ -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; @@ -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) diff --git a/phpmyfaq/login.php b/phpmyfaq/login.php index c073432abc..4b319cdb98 100644 --- a/phpmyfaq/login.php +++ b/phpmyfaq/login.php @@ -15,7 +15,6 @@ * @since 2012-02-12 */ -use phpMyFAQ\Configuration; use phpMyFAQ\Session; use phpMyFAQ\Template\TwigWrapper; use phpMyFAQ\Translation; @@ -26,7 +25,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $faqSession = new Session($faqConfig); $faqSession->setCurrentUser($user); diff --git a/phpmyfaq/news.php b/phpmyfaq/news.php index 6bbbee341b..6a35de86f5 100644 --- a/phpmyfaq/news.php +++ b/phpmyfaq/news.php @@ -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; @@ -42,7 +41,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $faqSession = new Session($faqConfig); $faqSession->setCurrentUser($user); diff --git a/phpmyfaq/open-questions.php b/phpmyfaq/open-questions.php index 4613cf7586..d6c23e14ab 100644 --- a/phpmyfaq/open-questions.php +++ b/phpmyfaq/open-questions.php @@ -16,7 +16,6 @@ */ use phpMyFAQ\Category; -use phpMyFAQ\Configuration; use phpMyFAQ\Helper\QuestionHelper; use phpMyFAQ\Session; use phpMyFAQ\Template\TwigWrapper; @@ -28,7 +27,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $faqSession = new Session($faqConfig); diff --git a/phpmyfaq/overview.php b/phpmyfaq/overview.php index 3ff3764143..48ca038871 100644 --- a/phpmyfaq/overview.php +++ b/phpmyfaq/overview.php @@ -15,7 +15,6 @@ * @since 2015-09-27 */ -use phpMyFAQ\Configuration; use phpMyFAQ\Helper\FaqHelper; use phpMyFAQ\Session; use phpMyFAQ\Template\CategoryNameTwigExtension; @@ -30,7 +29,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $faqSession = new Session($faqConfig); $faqSession->setCurrentUser($user); diff --git a/phpmyfaq/password.php b/phpmyfaq/password.php index 0f3174fc31..43a3425099 100644 --- a/phpmyfaq/password.php +++ b/phpmyfaq/password.php @@ -15,7 +15,6 @@ * @since 2012-03-26 */ -use phpMyFAQ\Configuration; use phpMyFAQ\Session; use phpMyFAQ\Template\TwigWrapper; @@ -24,7 +23,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $faqSession = new Session($faqConfig); $faqSession->userTracking('forgot_password', 0); diff --git a/phpmyfaq/privacy.php b/phpmyfaq/privacy.php index 8ed600206d..b5d498d61d 100644 --- a/phpmyfaq/privacy.php +++ b/phpmyfaq/privacy.php @@ -15,7 +15,6 @@ * @since 2023-01-22 */ -use phpMyFAQ\Configuration; use Symfony\Component\HttpFoundation\RedirectResponse; if (!defined('IS_VALID_PHPMYFAQ')) { @@ -23,10 +22,9 @@ 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); diff --git a/phpmyfaq/register.php b/phpmyfaq/register.php index aa90c959aa..6eb82f9bcc 100644 --- a/phpmyfaq/register.php +++ b/phpmyfaq/register.php @@ -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; @@ -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); diff --git a/phpmyfaq/request-removal.php b/phpmyfaq/request-removal.php index bc3384c01d..ee1d4f7603 100644 --- a/phpmyfaq/request-removal.php +++ b/phpmyfaq/request-removal.php @@ -15,7 +15,6 @@ * @since 2018-02-03 */ -use phpMyFAQ\Configuration; use phpMyFAQ\Session; use phpMyFAQ\Session\Token; use phpMyFAQ\Template\TwigWrapper; @@ -26,7 +25,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $faqSession = new Session($faqConfig); $faqSession->setCurrentUser($user); diff --git a/phpmyfaq/search.php b/phpmyfaq/search.php index 5f3fd98571..3dab460d00 100755 --- a/phpmyfaq/search.php +++ b/phpmyfaq/search.php @@ -16,7 +16,6 @@ */ use phpMyFAQ\Category; -use phpMyFAQ\Configuration; use phpMyFAQ\Faq; use phpMyFAQ\Faq\Permission; use phpMyFAQ\Filter; @@ -42,7 +41,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $faqSession = new Session($faqConfig); $faqSession->setCurrentUser($user); diff --git a/phpmyfaq/show.php b/phpmyfaq/show.php index f2cc037a39..1bb6f0ce76 100644 --- a/phpmyfaq/show.php +++ b/phpmyfaq/show.php @@ -16,7 +16,6 @@ */ use phpMyFAQ\Category; -use phpMyFAQ\Configuration; use phpMyFAQ\Filter; use phpMyFAQ\Helper\CategoryHelper; use phpMyFAQ\Language\Plurals; @@ -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); diff --git a/phpmyfaq/sitemap.php b/phpmyfaq/sitemap.php index 8a1703897a..70a5604768 100644 --- a/phpmyfaq/sitemap.php +++ b/phpmyfaq/sitemap.php @@ -16,7 +16,6 @@ * @since 2005-08-21 */ -use phpMyFAQ\Configuration; use phpMyFAQ\Filter; use phpMyFAQ\Session; use phpMyFAQ\Sitemap; @@ -31,7 +30,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $faqSession = new Session($faqConfig); $faqSession->setCurrentUser($user); diff --git a/phpmyfaq/sitemap.xml.php b/phpmyfaq/sitemap.xml.php index 6f1d76c5a1..b53baf9b89 100644 --- a/phpmyfaq/sitemap.xml.php +++ b/phpmyfaq/sitemap.xml.php @@ -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']])); diff --git a/phpmyfaq/src/services.php b/phpmyfaq/src/services.php new file mode 100644 index 0000000000..5c7184be0b --- /dev/null +++ b/phpmyfaq/src/services.php @@ -0,0 +1,30 @@ + + * @copyright 2024 phpMyFAQ Team + * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 + * @link https://www.phpmyfaq.de + * @since 2024-10-07 + */ + +use phpMyFAQ\Configuration; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; + +return static function (ContainerConfigurator $container): void { + // Parameters + $container->parameters(); + + // Services + $services = $container->services(); + + $services->set('phpmyfaq.configuration', Configuration::class) + ->factory([Configuration::class, 'getConfigurationInstance']); +}; diff --git a/phpmyfaq/startpage.php b/phpmyfaq/startpage.php index efedbdb90c..f510bf18bb 100755 --- a/phpmyfaq/startpage.php +++ b/phpmyfaq/startpage.php @@ -16,7 +16,6 @@ */ use phpMyFAQ\Category\Startpage; -use phpMyFAQ\Configuration; use phpMyFAQ\Faq\Statistics; use phpMyFAQ\Helper\CategoryHelper; use phpMyFAQ\Language\Plurals; @@ -32,7 +31,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $news = new News($faqConfig); $categoryHelper = new CategoryHelper(); diff --git a/phpmyfaq/ucp.php b/phpmyfaq/ucp.php index 273cc1c5db..32a9aa7b5c 100644 --- a/phpmyfaq/ucp.php +++ b/phpmyfaq/ucp.php @@ -15,7 +15,6 @@ * @since 2012-01-12 */ -use phpMyFAQ\Configuration; use phpMyFAQ\Services\Gravatar; use phpMyFAQ\Session; use phpMyFAQ\Session\Token; @@ -32,7 +31,7 @@ exit(); } -$faqConfig = Configuration::getConfigurationInstance(); +$faqConfig = $container->get('phpmyfaq.configuration'); $user = CurrentUser::getCurrentUser($faqConfig); $faqSession = new Session($faqConfig); $faqSession->setCurrentUser($user);