Skip to content

Commit ac1dc77

Browse files
authored
Merge pull request #366 from dotkernel/issue-365
Issue #365: Removed `laminas/laminas-i18n`
2 parents 3ae31cb + e6ba8b0 commit ac1dc77

File tree

7 files changed

+87
-17
lines changed

7 files changed

+87
-17
lines changed

composer.json

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
},
2929
"require": {
3030
"php": "~8.2.0 || ~8.3.0",
31-
"ext-gettext": "*",
3231
"dotkernel/dot-cache": "^4.3.0",
3332
"dotkernel/dot-cli": "^3.9.0",
3433
"dotkernel/dot-data-fixtures": "^1.4.0",
@@ -46,28 +45,26 @@
4645
"friendsofphp/proxy-manager-lts": "^1.0.18",
4746
"laminas/laminas-component-installer": "^3.5.0",
4847
"laminas/laminas-config-aggregator": "^1.18.0",
49-
"laminas/laminas-i18n": "^2.29.0",
50-
"laminas/laminas-math": "^3.8.1",
51-
"mezzio/mezzio": "^3.20.1",
48+
"mezzio/mezzio": "^3.21.0",
5249
"mezzio/mezzio-authentication-oauth2": "^2.11.0",
53-
"mezzio/mezzio-authorization-rbac": "^1.8.0",
54-
"mezzio/mezzio-cors": "^1.13.0",
55-
"mezzio/mezzio-fastroute": "^3.12.0",
50+
"mezzio/mezzio-authorization-rbac": "^1.9.0",
51+
"mezzio/mezzio-cors": "^1.14.0",
52+
"mezzio/mezzio-fastroute": "^3.13.0",
5653
"ramsey/uuid-doctrine": "^2.1.0",
5754
"roave/psr-container-doctrine": "^5.2.2"
5855
},
5956
"require-dev": {
6057
"filp/whoops": "^2.18.0",
61-
"laminas/laminas-coding-standard": "^3.0.1",
58+
"laminas/laminas-coding-standard": "^3.1.0",
6259
"laminas/laminas-development-mode": "^3.13.0",
6360
"mezzio/mezzio-tooling": "^2.10.1",
64-
"phpunit/phpunit": "^10.5.45",
65-
"roave/security-advisories": "dev-latest",
66-
"vincentlanglet/twig-cs-fixer": "^3.5.1",
67-
"phpstan/phpstan": "^2.1.11",
68-
"phpstan/phpstan-doctrine": "^2.0.2",
61+
"phpstan/phpstan": "^2.1.17",
62+
"phpstan/phpstan-doctrine": "^2.0.3",
6963
"phpstan/phpstan-phpunit": "^2.0.6",
70-
"symfony/var-dumper": "^7.2.3"
64+
"phpunit/phpunit": "^10.5.46",
65+
"roave/security-advisories": "dev-latest",
66+
"symfony/var-dumper": "^7.3.0",
67+
"vincentlanglet/twig-cs-fixer": "^3.7.1"
7168
},
7269
"autoload": {
7370
"psr-4": {

config/config.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88
'config_cache_path' => 'data/cache/config-cache.php',
99
];
1010

11+
/**
12+
* @see https://github.com/dotkernel/admin/issues/365
13+
*/
14+
if (! class_exists('\Laminas\I18n\View\Helper\AbstractTranslatorHelper')) {
15+
class_alias(
16+
Admin\App\Laminas\I18n\View\Helper\AbstractTranslatorHelper::class,
17+
'\Laminas\I18n\View\Helper\AbstractTranslatorHelper'
18+
);
19+
}
20+
if (! class_exists('\Laminas\I18n\Validator\IsFloat')) {
21+
class_alias(Admin\App\Laminas\I18n\Validator\IsFloat::class, '\Laminas\I18n\Validator\IsFloat');
22+
}
23+
1124
// @codingStandardsIgnoreStart
1225
$aggregator = new Laminas\ConfigAggregator\ConfigAggregator([
1326
// Laminas packages

src/Admin/src/Handler/Account/PostAccountLoginHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use Psr\Http\Server\RequestHandlerInterface;
2525
use Throwable;
2626

27+
use function assert;
28+
2729
class PostAccountLoginHandler implements RequestHandlerInterface
2830
{
2931
#[Inject(
@@ -40,7 +42,7 @@ public function __construct(
4042
protected AdminServiceInterface $adminService,
4143
protected AdminLoginServiceInterface $adminLoginService,
4244
protected RouterInterface $router,
43-
protected LaminasAuthenticationServiceInterface&AuthenticationServiceInterface $authenticationService,
45+
protected LaminasAuthenticationServiceInterface $authenticationService,
4446
protected FlashMessengerInterface $messenger,
4547
protected FormsPlugin $forms,
4648
protected LoginForm $loginForm,
@@ -50,6 +52,7 @@ public function __construct(
5052

5153
public function handle(ServerRequestInterface $request): ResponseInterface
5254
{
55+
assert($this->authenticationService instanceof AuthenticationServiceInterface);
5356
if ($this->authenticationService->hasIdentity()) {
5457
return new RedirectResponse($this->router->generateUri('app::index-redirect'));
5558
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Admin\App\Laminas\I18n\Validator;
6+
7+
use Laminas\Validator\AbstractValidator;
8+
9+
class IsFloat extends AbstractValidator
10+
{
11+
/**
12+
* @inheritDoc
13+
*/
14+
public function isValid($value): false
15+
{
16+
return false;
17+
}
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Admin\App\Laminas\I18n\View\Helper;
6+
7+
use Laminas\View\Helper\AbstractHelper;
8+
9+
abstract class AbstractTranslatorHelper extends AbstractHelper
10+
{
11+
public function getTranslator(): null
12+
{
13+
return null;
14+
}
15+
}

src/User/src/Handler/PostUserAvatarEditHandler.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
namespace Admin\User\Handler;
66

77
use Admin\App\Exception\NotFoundException;
8+
use Admin\App\Form\AbstractForm;
89
use Admin\User\Form\EditUserAvatarForm;
910
use Admin\User\Form\EditUserForm;
1011
use Admin\User\Service\UserAvatarServiceInterface;
12+
use Admin\User\Service\UserRoleServiceInterface;
1113
use Admin\User\Service\UserServiceInterface;
1214
use Core\App\Message;
15+
use Core\User\Entity\UserRole;
16+
use Core\User\Enum\UserRoleEnum;
1317
use Dot\DependencyInjection\Attribute\Inject;
1418
use Dot\FlashMessenger\FlashMessengerInterface;
1519
use Dot\Log\Logger;
@@ -23,12 +27,18 @@
2327
use Psr\Http\Server\RequestHandlerInterface;
2428
use Throwable;
2529

30+
use function array_filter;
31+
use function array_map;
2632
use function array_merge;
2733

34+
/**
35+
* @phpstan-import-type SelectDataType from AbstractForm
36+
*/
2837
class PostUserAvatarEditHandler implements RequestHandlerInterface
2938
{
3039
#[Inject(
3140
UserServiceInterface::class,
41+
UserRoleServiceInterface::class,
3242
UserAvatarServiceInterface::class,
3343
RouterInterface::class,
3444
TemplateRendererInterface::class,
@@ -39,6 +49,7 @@ class PostUserAvatarEditHandler implements RequestHandlerInterface
3949
)]
4050
public function __construct(
4151
protected UserServiceInterface $userService,
52+
protected UserRoleServiceInterface $userRoleService,
4253
protected UserAvatarServiceInterface $userAvatarService,
4354
protected RouterInterface $router,
4455
protected TemplateRendererInterface $template,
@@ -59,6 +70,19 @@ public function handle(ServerRequestInterface $request): ResponseInterface
5970
return new EmptyResponse(StatusCodeInterface::STATUS_NOT_FOUND);
6071
}
6172

73+
/** @var UserRole[] $userRoles */
74+
$userRoles = $this->userRoleService->getUserRoleRepository()->findAll();
75+
$userRoles = array_map(
76+
/** @return SelectDataType */
77+
fn (UserRole $userRole): array => [
78+
'label' => $userRole->getName()->value,
79+
'value' => $userRole->getUuid()->toString(),
80+
'selected' => $user->hasRole($userRole),
81+
],
82+
$userRoles
83+
);
84+
$userRoles = array_filter($userRoles, fn (array $role) => $role['label'] !== UserRoleEnum::Guest->value);
85+
6286
$this->editUserAvatarForm
6387
->setAttribute(
6488
'action',
@@ -69,7 +93,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface
6993
->setAttribute(
7094
'action',
7195
$this->router->generateUri('user::user-edit', ['uuid' => $user->getUuid()->toString()])
72-
);
96+
)
97+
->setRoles($userRoles);
7398

7499
try {
75100
$this->editUserAvatarForm->setData(

test/Unit/Admin/Adapter/AuthenticationAdapterTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ public function testWillNotAuthenticateWithoutValidConfig(): void
100100
/**
101101
* @throws MockObjectException
102102
* @throws ORMException
103-
* @group testing
104103
*/
105104
public function testWillNotAuthenticateWithInvalidIdentityClassConfig(): void
106105
{

0 commit comments

Comments
 (0)