Skip to content

Commit 2db2df3

Browse files
committed
Merge remote-tracking branch 'origin/5.0' into change-php-api-link
2 parents 9fd16a8 + f1a8e3e commit 2db2df3

91 files changed

Lines changed: 1572 additions & 347 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/code_samples.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jobs:
99
runs-on: "ubuntu-22.04"
1010
strategy:
1111
matrix:
12+
fail-fast: false
1213
php:
1314
- "8.4" # Upper supported version
1415
- "8.3" # Lower supported version
@@ -45,12 +46,15 @@ jobs:
4546
dependency-versions: highest
4647

4748
- name: Run PHPStan analysis
49+
continue-on-error: true
4850
run: composer phpstan
4951

5052
- name: Run Deptrac analysis
53+
continue-on-error: true
5154
run: composer deptrac
5255

5356
- name: Run Rector check
57+
continue-on-error: true
5458
run: composer check-rector
5559

5660
code-samples-inclusion-check:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
App\GraphQL\Schema\MyFieldDefinitionMapper:
3+
decorates: Ibexa\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\DecoratingFieldDefinitionMapper
4+
arguments:
5+
$innerMapper: '@.inner'

code_samples/api/graphql/src/GraphQL/Schema/MyCustomFieldDefinitionMapper.php

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\GraphQL\Schema;
4+
5+
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
6+
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
7+
use Ibexa\Contracts\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\FieldDefinitionMapper;
8+
use Ibexa\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\DecoratingFieldDefinitionMapper;
9+
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
10+
11+
class MyFieldDefinitionMapper extends DecoratingFieldDefinitionMapper implements FieldDefinitionMapper
12+
{
13+
protected function getFieldTypeIdentifier(): string
14+
{
15+
return 'my_field_type';
16+
}
17+
18+
public function mapToFieldValueInputType(ContentType $contentType, FieldDefinition $fieldDefinition): ?string
19+
{
20+
if (!$this->canMap($fieldDefinition)) {
21+
return parent::mapToFieldValueInputType($contentType, $fieldDefinition);
22+
}
23+
24+
return $this->nameMyFieldInputType($contentType, $fieldDefinition);
25+
}
26+
27+
private function nameMyFieldInputType(ContentType $contentType, FieldDefinition $fieldDefinition): string
28+
{
29+
$converter = new CamelCaseToSnakeCaseNameConverter(null, false);
30+
31+
return sprintf(
32+
'%s%sInput',
33+
$converter->denormalize($contentType->identifier),
34+
$converter->denormalize($fieldDefinition->identifier)
35+
);
36+
}
37+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@use '@ibexa-admin-ui/src/bundle/Resources/public/scss/_alerts.scss' as *;
2+
3+
.ibexa-alert {
4+
&--notification {
5+
@extend .ibexa-alert--info;
6+
}
7+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
framework:
2+
notifier:
3+
chatter_transports:
4+
slack: '%env(SLACK_DSN)%'
5+
ibexa:
6+
system:
7+
default:
8+
notifier:
9+
subscriptions:
10+
# The configuration below is added to the `default` scope without overriding the one defined in ibexa.yaml
11+
# Custom subscriptions:
12+
Ibexa\OrderManagement\Notification\OrderStatusChange:
13+
channels:
14+
- chat
15+
Ibexa\Payment\Notification\PaymentStatusChange:
16+
channels:
17+
- chat
18+
Ibexa\Shipping\Notification\ShipmentStatusChange:
19+
channels:
20+
- chat
21+
App\Notifications\CommandExecuted:
22+
channels:
23+
- ibexa
24+
- email
25+
- log
26+
admin_group:
27+
notifier:
28+
subscriptions:
29+
# The configuration below is added to the `admin_group` scope without overriding the one defined in ibexa_admin_ui.yaml
30+
# Custom subscriptions:
31+
App\Notifications\CommandExecuted:
32+
channels:
33+
- ibexa
34+
- email
35+
- log
36+
App\Notifications\ControllerFeedback:
37+
channels:
38+
- browser
39+
storefront_group:
40+
notifier:
41+
subscriptions:
42+
# The configuration defined in ibexa.yaml for `default` scope is repeated as the configuration below overrides it
43+
Ibexa\Contracts\User\Notification\UserPasswordReset:
44+
channels:
45+
- email
46+
Ibexa\Contracts\User\Notification\UserInvitation:
47+
channels:
48+
- email
49+
Ibexa\Contracts\FormBuilder\Notifications\FormSubmitted:
50+
channels:
51+
- email
52+
# Custom subscriptions:
53+
Ibexa\OrderManagement\Notification\OrderStatusChange:
54+
channels:
55+
- chat
56+
Ibexa\Payment\Notification\PaymentStatusChange:
57+
channels:
58+
- chat
59+
Ibexa\Shipping\Notification\ShipmentStatusChange:
60+
channels:
61+
- chat
62+
App\Notifications\CommandExecuted:
63+
channels:
64+
- ibexa
65+
- email
66+
- log
67+
App\Notifications\ControllerFeedback:
68+
channels:
69+
- browser
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
App\Notifier\Channel\LogChannel:
3+
tags:
4+
- { name: 'notifier.channel', channel: 'log' }
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types=1);
2+
3+
use App\Notifications\MyNotification; // extends Symfony\Component\Notifier\Notification\Notification
4+
use Ibexa\Contracts\Notifications\Value\Notification\SymfonyNotificationAdapter;
5+
use Ibexa\Contracts\Notifications\Value\Recipent\SymfonyRecipientAdapter;
6+
use Ibexa\Contracts\Notifications\Value\Recipent\UserRecipient;
7+
8+
$subject = 'My subject';
9+
10+
/** @var \Ibexa\Contracts\Notifications\Service\NotificationServiceInterface $notificationService */
11+
/** @var \Ibexa\Contracts\Core\Repository\UserService $userService */
12+
/** @var \Ibexa\Contracts\Core\Repository\PermissionResolver $permissionResolver */
13+
$notificationService->send(
14+
new SymfonyNotificationAdapter(new MyNotification($subject)),
15+
[new SymfonyRecipientAdapter(new UserRecipient($userService->loadUser($permissionResolver->getCurrentUserReference()->getUserId())))],
16+
);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Command;
6+
7+
use App\Notifications\CommandExecuted;
8+
use Ibexa\Contracts\Core\Repository\UserService;
9+
use Ibexa\Contracts\Notifications\Service\NotificationServiceInterface;
10+
use Ibexa\Contracts\Notifications\Value\Notification\SymfonyNotificationAdapter;
11+
use Ibexa\Contracts\Notifications\Value\Recipent\SymfonyRecipientAdapter;
12+
use Ibexa\Contracts\Notifications\Value\Recipent\UserRecipient;
13+
use Symfony\Component\Console\Attribute\AsCommand;
14+
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Input\InputInterface;
16+
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Notifier\Recipient\RecipientInterface;
18+
19+
#[AsCommand(name: 'app:send_notification', description: 'Example of command sending a notification')]
20+
class NotificationSenderCommand extends Command
21+
{
22+
/** @param array<int, string> $recipientLogins */
23+
public function __construct(
24+
private readonly NotificationServiceInterface $notificationService,
25+
private readonly UserService $userService,
26+
private readonly array $recipientLogins = ['admin'],
27+
) {
28+
parent::__construct();
29+
}
30+
31+
protected function execute(InputInterface $input, OutputInterface $output): int
32+
{
33+
/** @var array<int, \Throwable> $exceptions */
34+
$exceptions = [];
35+
36+
try {
37+
// Do something
38+
if (random_int(0, 1) == 1) {
39+
throw new \RuntimeException('Something went wrong');
40+
}
41+
$exitCode = Command::SUCCESS;
42+
} catch (\Exception $exception) {
43+
$exceptions[] = $exception;
44+
$exitCode = Command::FAILURE;
45+
}
46+
47+
$recipients = [];
48+
foreach ($this->recipientLogins as $login) {
49+
try {
50+
$user = $this->userService->loadUserByLogin($login);
51+
$recipients[] = new UserRecipient($user);
52+
} catch (\Exception $exception) {
53+
$exceptions[] = $exception;
54+
}
55+
}
56+
57+
$this->notificationService->send(
58+
new SymfonyNotificationAdapter(new CommandExecuted($this, $exitCode, $exceptions)),
59+
array_map(
60+
static fn (RecipientInterface $recipient): SymfonyRecipientAdapter => new SymfonyRecipientAdapter($recipient),
61+
$recipients
62+
)
63+
);
64+
65+
return $exitCode;
66+
}
67+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\Controller;
4+
5+
use App\Notifications\ControllerFeedback;
6+
use Ibexa\Contracts\Notifications\Service\NotificationServiceInterface;
7+
use Ibexa\Contracts\Notifications\Value\Notification\SymfonyNotificationAdapter;
8+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9+
use Symfony\Component\HttpFoundation\Response;
10+
use Symfony\Component\Routing\Attribute\Route;
11+
12+
class NotificationSenderController extends AbstractController
13+
{
14+
public function __construct(
15+
private readonly NotificationServiceInterface $notificationService,
16+
) {
17+
}
18+
19+
#[Route('/notification-sender')]
20+
public function index(): Response
21+
{
22+
$this->notificationService->send(
23+
new SymfonyNotificationAdapter((new ControllerFeedback('Message sent from controller'))->emoji('👍')),
24+
);
25+
26+
return $this->render('@ibexadesign/notification-sender-controller.html.twig');
27+
}
28+
}

0 commit comments

Comments
 (0)