Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"require": {
"php": "^8.1",
"phplist/core": "dev-subscribepage",
"phplist/core": "dev-dev",
"friendsofsymfony/rest-bundle": "*",
"symfony/test-pack": "^1.0",
"symfony/process": "^6.4",
Expand Down
10 changes: 7 additions & 3 deletions config/services/managers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ services:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Messaging\Service\MessageManager:
PhpList\Core\Domain\Messaging\Service\Manager\MessageManager:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Messaging\Service\TemplateManager:
PhpList\Core\Domain\Messaging\Service\Manager\TemplateManager:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Messaging\Service\TemplateImageManager:
PhpList\Core\Domain\Messaging\Service\Manager\TemplateImageManager:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Messaging\Service\Manager\BounceRegexManager:
autowire: true
autoconfigure: true

Expand Down
4 changes: 4 additions & 0 deletions config/services/normalizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ services:
PhpList\RestBundle\Subscription\Serializer\SubscribePageNormalizer:
tags: [ 'serializer.normalizer' ]
autowire: true

PhpList\RestBundle\Messaging\Serializer\BounceRegexNormalizer:
tags: [ 'serializer.normalizer' ]
autowire: true
246 changes: 246 additions & 0 deletions src/Messaging/Controller/BounceRegexController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
<?php

declare(strict_types=1);

namespace PhpList\RestBundle\Messaging\Controller;

use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Messaging\Service\Manager\BounceRegexManager;
use PhpList\Core\Security\Authentication;
use PhpList\RestBundle\Common\Controller\BaseController;
use PhpList\RestBundle\Common\Validator\RequestValidator;
use PhpList\RestBundle\Messaging\Request\CreateBounceRegexRequest;
use PhpList\RestBundle\Messaging\Serializer\BounceRegexNormalizer;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

/**
* Manage bounce regular expressions.
*/
#[Route('/bounces/regex', name: 'bounce_regex_')]
class BounceRegexController extends BaseController
{
public function __construct(
Authentication $authentication,
RequestValidator $validator,
private readonly BounceRegexManager $manager,
private readonly BounceRegexNormalizer $normalizer,
) {
parent::__construct($authentication, $validator);
}

#[Route('', name: 'get_list', methods: ['GET'])]
#[OA\Get(
path: '/api/v2/bounces/regex',
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
'Returns a JSON list of all bounce regex rules.',
summary: 'Gets a list of all bounce regex rules.',
tags: ['bounces'],
parameters: [
new OA\Parameter(
name: 'php-auth-pw',
description: 'Session key obtained from login',
in: 'header',
required: true,
schema: new OA\Schema(type: 'string')
),
],
responses: [
new OA\Response(
response: 200,
description: 'Success',
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(ref: '#/components/schemas/BounceRegex')
)
),
new OA\Response(
response: 403,
description: 'Failure',
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
)
]
)]
public function list(Request $request): JsonResponse
{
$this->requireAuthentication($request);
$items = $this->manager->getAll();
$normalized = array_map(fn($bounceRegex) => $this->normalizer->normalize($bounceRegex), $items);

return $this->json($normalized, Response::HTTP_OK);
}

#[Route('/{regexHash}', name: 'get_one', methods: ['GET'])]
#[OA\Get(
path: '/api/v2/bounces/regex/{regexHash}',
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
'Returns a bounce regex by its hash.',
summary: 'Get a bounce regex by its hash',
tags: ['bounces'],
parameters: [
new OA\Parameter(
name: 'php-auth-pw',
description: 'Session key obtained from login',
in: 'header',
required: true,
schema: new OA\Schema(type: 'string')
),
new OA\Parameter(
name: 'regexHash',
description: 'Regex hash',
in: 'path',
required: true,
schema: new OA\Schema(type: 'string')
),
],
responses: [
new OA\Response(
response: 200,
description: 'Success',
content: new OA\JsonContent(ref: '#/components/schemas/BounceRegex')
),
new OA\Response(
response: 403,
description: 'Failure',
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
),
new OA\Response(
response: 404,
description: 'Failure',
content: new OA\JsonContent(ref: '#/components/schemas/NotFoundErrorResponse')
)
]
)]
public function getOne(Request $request, string $regexHash): JsonResponse
{
$this->requireAuthentication($request);
$entity = $this->manager->getByHash($regexHash);
if (!$entity) {
throw $this->createNotFoundException('Bounce regex not found.');
}

return $this->json($this->normalizer->normalize($entity), Response::HTTP_OK);
}

#[Route('', name: 'create_or_update', methods: ['POST'])]
#[OA\Post(
path: '/api/v2/bounces/regex',
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
'Creates a new bounce regex or updates an existing one (matched by regex hash).',
summary: 'Create or update a bounce regex',
requestBody: new OA\RequestBody(
description: 'Create or update a bounce regex rule.',
required: true,
content: new OA\JsonContent(
required: ['regex'],
properties: [
new OA\Property(property: 'regex', type: 'string', example: '/mailbox is full/i'),
new OA\Property(property: 'action', type: 'string', example: 'delete', nullable: true),
new OA\Property(property: 'list_order', type: 'integer', example: 0, nullable: true),
new OA\Property(property: 'admin', type: 'integer', example: 1, nullable: true),
new OA\Property(property: 'comment', type: 'string', example: 'Auto-generated', nullable: true),
new OA\Property(property: 'status', type: 'string', example: 'active', nullable: true),
],
type: 'object'
)
),
tags: ['bounces'],
parameters: [
new OA\Parameter(
name: 'php-auth-pw',
description: 'Session key obtained from login',
in: 'header',
required: true,
schema: new OA\Schema(type: 'string')
),
],
responses: [
new OA\Response(
response: 201,
description: 'Success',
content: new OA\JsonContent(ref: '#/components/schemas/BounceRegex')
),
new OA\Response(
response: 403,
description: 'Failure',
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
),
new OA\Response(
response: 422,
description: 'Failure',
content: new OA\JsonContent(ref: '#/components/schemas/ValidationErrorResponse')
),
]
)]
public function createOrUpdate(Request $request): JsonResponse
{
$this->requireAuthentication($request);
/** @var CreateBounceRegexRequest $dto */
$dto = $this->validator->validate($request, CreateBounceRegexRequest::class);

$entity = $this->manager->createOrUpdateFromPattern(
regex: $dto->regex,
action: $dto->action,
listOrder: $dto->listOrder,
adminId: $dto->admin,
comment: $dto->comment,
status: $dto->status
);

return $this->json($this->normalizer->normalize($entity), Response::HTTP_CREATED);
}

#[Route('/{regexHash}', name: 'delete', methods: ['DELETE'])]
#[OA\Delete(
path: '/api/v2/bounces/regex/{regexHash}',
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
'Delete a bounce regex by its hash.',
summary: 'Delete a bounce regex by its hash',
tags: ['bounces'],
parameters: [
new OA\Parameter(
name: 'php-auth-pw',
description: 'Session key obtained from login',
in: 'header',
required: true,
schema: new OA\Schema(type: 'string')
),
new OA\Parameter(
name: 'regexHash',
description: 'Regex hash',
in: 'path',
required: true,
schema: new OA\Schema(type: 'string')
),
],
responses: [
new OA\Response(
response: Response::HTTP_NO_CONTENT,
description: 'Success'
),
new OA\Response(
response: 403,
description: 'Failure',
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
),
new OA\Response(
response: 404,
description: 'Failure',
content: new OA\JsonContent(ref: '#/components/schemas/NotFoundErrorResponse')
)
]
)]
public function delete(Request $request, string $regexHash): JsonResponse
{
$this->requireAuthentication($request);
$entity = $this->manager->getByHash($regexHash);
if (!$entity) {
throw $this->createNotFoundException('Bounce regex not found.');
}
$this->manager->delete($entity);

return $this->json(null, Response::HTTP_NO_CONTENT);
}
}
2 changes: 1 addition & 1 deletion src/Messaging/Controller/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Messaging\Model\Template;
use PhpList\Core\Domain\Messaging\Service\TemplateManager;
use PhpList\Core\Domain\Messaging\Service\Manager\TemplateManager;
use PhpList\Core\Security\Authentication;
use PhpList\RestBundle\Common\Controller\BaseController;
use PhpList\RestBundle\Common\Service\Provider\PaginatedDataProvider;
Expand Down
15 changes: 15 additions & 0 deletions src/Messaging/OpenApi/SwaggerSchemasResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@
],
type: 'object'
)]
#[OA\Schema(
schema: 'BounceRegex',
properties: [
new OA\Property(property: 'id', type: 'integer', example: 10),
new OA\Property(property: 'regex', type: 'string', example: '/mailbox is full/i'),
new OA\Property(property: 'regex_hash', type: 'string', example: 'd41d8cd98f00b204e9800998ecf8427e'),
new OA\Property(property: 'action', type: 'string', example: 'delete', nullable: true),
new OA\Property(property: 'list_order', type: 'integer', example: 0, nullable: true),
new OA\Property(property: 'admin_id', type: 'integer', example: 1, nullable: true),
new OA\Property(property: 'comment', type: 'string', example: 'Auto-generated rule', nullable: true),
new OA\Property(property: 'status', type: 'string', example: 'active', nullable: true),
new OA\Property(property: 'count', type: 'integer', example: 5, nullable: true),
],
type: 'object'
)]
class SwaggerSchemasResponse
{
}
42 changes: 42 additions & 0 deletions src/Messaging/Request/CreateBounceRegexRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace PhpList\RestBundle\Messaging\Request;

use PhpList\RestBundle\Common\Request\RequestInterface;
use Symfony\Component\Validator\Constraints as Assert;

class CreateBounceRegexRequest implements RequestInterface
{
#[Assert\NotBlank]
#[Assert\Type('string')]
public string $regex;

#[Assert\Type('string')]
public ?string $action = null;

#[Assert\Type('integer')]
public ?int $listOrder = 0;

#[Assert\Type('integer')]
public ?int $admin = null;

#[Assert\Type('string')]
public ?string $comment = null;

#[Assert\Type('string')]
public ?string $status = null;

public function getDto(): array
{
return [
'regex' => $this->regex,
'action' => $this->action,
'listOrder' => $this->listOrder,
'admin' => $this->admin,
'comment' => $this->comment,
'status' => $this->status,
];
}
}
Loading
Loading