Skip to content

Commit

Permalink
Merge tag '1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolineus committed Feb 7, 2024
2 parents eaf645f + 266b02e commit 0770e97
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 24 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/diagnostics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ jobs:
fail-fast: false
matrix:
include:
- php: 7.4
output: '-o github-action -o default'
phpcq_install: 'install'
- php: 8.0
output: '-o default'
- php: 8.1
output: '-o github-action default'
phpcq_install: 'update'
- php: 8.2
output: '-o github-action default'
phpcq_install: 'update'
- php: 8.3
output: '-o github-action default'
phpcq_install: 'update'

steps:
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@

# Changelog

## [1.2.0] - 2024-02-07

### Changed

- Bump dependencies to Contao `^4.13 || ^5.2` and Symfony `^5.4 || ^6.4`
- Require PHP 8.1

### Fixed

- Use token checker for legacy `BE_USER_LOGGED_IN` and `FE_USER_LOGGED_IN` constants

## [1.1.3] - 2024-02-07

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
},
"extra": {
"branch-alias": {
"dev-develop": "1.2.x-dev",
"dev-master": "1.1.x-dev"
"dev-develop": "1.3.x-dev",
"dev-master": "1.2.x-dev"
},
"contao-manager-plugin": "Netzmacht\\Contao\\PageContext\\ContaoManager\\Plugin"
}
Expand Down
3 changes: 3 additions & 0 deletions spec/Request/ContaoPageContextInitializerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\Image\PictureFactoryInterface;
use Contao\CoreBundle\Security\Authentication\Token\TokenChecker;
use Netzmacht\Contao\PageContext\Request\ContaoPageContextInitializer;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
use PhpSpec\ObjectBehavior;
Expand All @@ -20,13 +21,15 @@ public function let(
PictureFactoryInterface $pictureFactory,
RepositoryManager $repositoryManager,
LoggerInterface $logger,
TokenChecker $tokenChecker,
): void {
$this->beConstructedWith(
$translator,
$framework,
$pictureFactory,
$repositoryManager,
$logger,
$tokenChecker,
);
}

Expand Down
22 changes: 5 additions & 17 deletions src/Request/ContaoPageContextInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\Image\PictureFactoryInterface;
use Contao\CoreBundle\Monolog\ContaoContext;
use Contao\CoreBundle\Security\Authentication\Token\TokenChecker;
use Contao\LayoutModel;
use Contao\PageModel;
use Contao\PageRegular;
Expand All @@ -22,7 +23,6 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\LocaleAwareInterface;

use function array_merge;
use function assert;
use function define;
use function defined;
Expand All @@ -36,33 +36,21 @@
*/
final class ContaoPageContextInitializer implements PageContextInitializer
{
/**
* Default config.
*
* @var array<string,bool>
*/
private array $defaults = [
'BE_USER_LOGGED_IN' => false,
'FE_USER_LOGGED_IN' => false,
];

/**
* @param LocaleAwareInterface $translator Translator.
* @param ContaoFramework $framework Contao framework.
* @param PictureFactoryInterface $pictureFactory Picture factory.
* @param RepositoryManager $repositoryManager Repository manager.
* @param LoggerInterface $logger Logger.
* @param array<string,bool> $defaults Default config to override default configs.
*/
public function __construct(
private readonly LocaleAwareInterface $translator,
private readonly ContaoFramework $framework,
private readonly PictureFactoryInterface $pictureFactory,
private readonly RepositoryManager $repositoryManager,
private readonly LoggerInterface $logger,
array $defaults = [],
private readonly TokenChecker $tokenChecker,
) {
$this->defaults = array_merge($this->defaults, $defaults);
}

/**
Expand All @@ -85,19 +73,19 @@ public function initialize(PageContext $context, Request $request): void
/**
* Initialize user logged in constants set by default.
*
* You can't trust this constants, as only defaults values are set right now.
* You can't trust these constants, as only defaults values are set right now.
*/
private function initializeUserLoggedInConstants(): void
{
if (! defined('BE_USER_LOGGED_IN')) {
define('BE_USER_LOGGED_IN', $this->defaults['BE_USER_LOGGED_IN']);
define('BE_USER_LOGGED_IN', $this->tokenChecker->isPreviewMode());
}

if (defined('FE_USER_LOGGED_IN')) {
return;
}

define('FE_USER_LOGGED_IN', $this->defaults['FE_USER_LOGGED_IN']);
define('FE_USER_LOGGED_IN', $this->tokenChecker->hasFrontendUser());
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<argument type="service" id="contao.image.picture_factory"/>
<argument type="service" id="netzmacht.contao_toolkit.repository_manager"/>
<argument type="service" id="logger"/>
<argument type="service" id="contao.security.token_checker"/>
</service>

<service id="Netzmacht\Contao\PageContext\Security\PageContextVoter">
Expand Down

0 comments on commit 0770e97

Please sign in to comment.