Skip to content

Commit 9e9bf87

Browse files
authored
Merge pull request #1 from FmiKL/release/symfony6-compatibility
Release Symfony 6 compatibility
2 parents fb9208a + 520230b commit 9e9bf87

8 files changed

Lines changed: 138 additions & 105 deletions

File tree

Entity/Newsletter.php

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,26 @@
77
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
88
use Symfony\Component\Validator\Constraints as Assert;
99

10-
/**
11-
* @ORM\Entity(repositoryClass=NewsletterRepository::class)
12-
* @UniqueEntity(fields={"token", "email"})
13-
*/
10+
#[ORM\Entity(repositoryClass: NewsletterRepository::class)]
11+
#[UniqueEntity(fields: ['token', 'email'])]
1412
class Newsletter
1513
{
16-
/**
17-
* @ORM\Id
18-
* @ORM\GeneratedValue
19-
* @ORM\Column(type="integer")
20-
*/
14+
#[ORM\Id]
15+
#[ORM\GeneratedValue]
16+
#[ORM\Column]
2117
private ?int $id = null;
2218

23-
/**
24-
* @ORM\Column(type="datetime_immutable", options={"default"="CURRENT_TIMESTAMP"})
25-
*/
19+
#[ORM\Column(type: 'datetime_immutable', options: ['default' => 'CURRENT_TIMESTAMP'])]
2620
private $created_at;
2721

28-
/**
29-
* @ORM\Column(type="string", length=255, unique=true)
30-
* @Assert\Email
31-
*/
22+
#[ORM\Column(length: 255, unique: true)]
23+
#[Assert\Email]
3224
private ?string $email = null;
3325

34-
/**
35-
* @ORM\Column(type="string", length=255, nullable=true, unique=true)
36-
*/
26+
#[ORM\Column(length: 255, nullable: true, unique: true)]
3727
private ?string $token = null;
3828

39-
/**
40-
* @ORM\Column(type="boolean")
41-
*/
29+
#[ORM\Column]
4230
private ?bool $is_confirmed = null;
4331

4432
public function __construct()
@@ -69,7 +57,7 @@ public function getEmail(): ?string
6957
return $this->email;
7058
}
7159

72-
public function setEmail(string $email): self
60+
public function setEmail(string $email): static
7361
{
7462
$this->email = $email;
7563

@@ -81,7 +69,7 @@ public function getToken(): ?string
8169
return $this->token;
8270
}
8371

84-
public function setToken(?string $token): self
72+
public function setToken(?string $token): static
8573
{
8674
$this->token = $token;
8775

@@ -93,7 +81,7 @@ public function getIsConfirmed(): ?bool
9381
return $this->is_confirmed;
9482
}
9583

96-
public function setIsConfirmed(bool $is_confirmed): self
84+
public function setIsConfirmed(bool $is_confirmed): static
9785
{
9886
$this->is_confirmed = $is_confirmed;
9987

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Copyright 2022 Mikael Fourré
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8+
9+
Join Us

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# NewsletterBundle
2+
3+
## About
4+
5+
This project is an **application bundle** for Symfony, designed to be intrinsically integrated into an existing application. It revolves around a newsletter management system, enabling the efficient dispatch of information and announcements to subscribed users.
6+
7+
## Configuration
8+
9+
### Installation
10+
11+
Clone the repository into your Symfony project:
12+
13+
```shell
14+
git clone https://github.com/mikael-fourre/NewsletterBundle
15+
```
16+
17+
Ensure the bundle is registered in your `config/bundles.php` file:
18+
19+
```php
20+
return [
21+
// ...
22+
App\Bundle\NewsletterBundle\NewsletterBundle::class => ['all' => true],
23+
];
24+
```
25+
26+
### Routing Configuration
27+
28+
Add the bundle's routes to your routing configuration.
29+
30+
```yaml
31+
# config/routes.yaml
32+
33+
newsletter_bundle:
34+
resource: '@NewsletterBundle/config/routes.yaml'
35+
```
36+
37+
The routes provided by the bundle are:
38+
39+
- `newsletter_subscribe`: Handles newsletter subscriptions
40+
- `newsletter_confirm`: Manages subscription confirmations
41+
- `newsletter_unsubscribe`: Manages unsubscriptions
42+
- `newsletter_send`: Sends newsletters to all subscribed users (admin access only)
43+
44+
### Template Configuration
45+
46+
Configure the template paths by adjusting your `twig.yaml` file to recognize the NewsletterBundle's templates.
47+
48+
```yaml
49+
# config/packages/twig.yaml
50+
51+
twig:
52+
paths:
53+
'%kernel.project_dir%/src/Bundle/NewsletterBundle/templates': NewsletterBundle
54+
```
55+
56+
### Parameters Configuration
57+
58+
Define custom parameters in your services.yaml file to configure the contact email address.
59+
60+
```yaml
61+
# config/services.yaml
62+
63+
parameters:
64+
contact_email: contact@domain.fr
65+
```
66+
67+
### Security Configuration
68+
69+
Secure the administration route by adjusting your `security.yaml` file.
70+
71+
```yaml
72+
# config/packages/security.yaml
73+
74+
security:
75+
access_control:
76+
- { path: ^/admin, roles: ROLE_ADMIN }
77+
```
78+
79+
## Usage
80+
81+
- **Subscription**: Send a POST request to `/newsletter/subscribe`
82+
- **Confirmation**: Redirect users to `/newsletter/confirm`
83+
- **Unsubscription**: Use `/newsletter/unsubscribe` for unsubscriptions
84+
- **Newsletter Sending** (admin only): A POST request to `/admin/newsletter/send` sends newsletters
85+
86+
## Contributing
87+
88+
Contributions are always welcome! To contribute:
89+
90+
- Fork the project
91+
- Create a branch for your modifications
92+
- Submit a Pull Request
93+
94+
## Support
95+
96+
Should you encounter issues or have questions, feel free to open an issue on GitHub.
97+
98+
## License
99+
100+
This project is licensed under the terms of the [MIT License](LICENSE). For more information, please refer to the file.

Service/ConfirmationService.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,14 @@
1111
*/
1212
class ConfirmationService
1313
{
14-
/**
15-
* @var NewsletterRepository
16-
*/
17-
private $newsletterRepository;
18-
19-
/**
20-
* @var EntityManagerInterface
21-
*/
22-
private $entityManager;
23-
2414
/**
2515
* @param NewsletterRepository $newsletterRepository
2616
* @param EntityManagerInterface $entityManager
2717
*/
2818
public function __construct(
29-
NewsletterRepository $newsletterRepository,
30-
EntityManagerInterface $entityManager
31-
) {
32-
$this->newsletterRepository = $newsletterRepository;
33-
$this->entityManager = $entityManager;
34-
}
19+
private NewsletterRepository $newsletterRepository,
20+
private EntityManagerInterface $entityManager
21+
){}
3522

3623
/**
3724
* Confirm a newsletter subscription using a token.

Service/MailerService.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,12 @@ class MailerService
2424
*/
2525
private const NEWS_TEMPLATE_PATH = '@NewsletterBundle/emails/news.html.twig';
2626

27-
/**
28-
* @var MailerInterface
29-
*/
30-
private $mailer;
31-
3227
/**
3328
* @param MailerInterface $mailer
3429
*/
35-
public function __construct(MailerInterface $mailer)
36-
{
37-
$this->mailer = $mailer;
38-
}
30+
public function __construct(
31+
private MailerInterface $mailer
32+
){}
3933

4034
/**
4135
* Send a newsletter email.

Service/NewsletterService.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,14 @@
99
*/
1010
class NewsletterService
1111
{
12-
/**
13-
* @var MailerService
14-
*/
15-
private $mailerService;
16-
17-
/**
18-
* @var NewsletterRepository
19-
*/
20-
private $newsletterRepository;
21-
2212
/**
2313
* @param MailerService $mailerService
2414
* @param NewsletterRepository $newsletterRepository
2515
*/
2616
public function __construct(
27-
MailerService $mailerService,
28-
NewsletterRepository $newsletterRepository
29-
) {
30-
$this->mailerService = $mailerService;
31-
$this->newsletterRepository = $newsletterRepository;
32-
}
17+
private MailerService $mailerService,
18+
private NewsletterRepository $newsletterRepository
19+
){}
3320

3421
/**
3522
* Send a newsletter to all confirmed subscribers.

Service/SubscriptionService.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,16 @@
1313
*/
1414
class SubscriptionService
1515
{
16-
/**
17-
* @var EntityManagerInterface
18-
*/
19-
private $entityManager;
20-
21-
/**
22-
* @var NewsletterRepository
23-
*/
24-
private $newsletterRepository;
25-
26-
/**
27-
* @var LoggerInterface
28-
*/
29-
private $logger;
30-
3116
/**
3217
* @param EntityManagerInterface $entityManager
3318
* @param NewsletterRepository $newsletterRepository
3419
* @param LoggerInterface $logger
3520
*/
3621
public function __construct(
37-
EntityManagerInterface $entityManager,
38-
NewsletterRepository $newsletterRepository,
39-
LoggerInterface $logger
40-
) {
41-
$this->entityManager = $entityManager;
42-
$this->newsletterRepository = $newsletterRepository;
43-
$this->logger = $logger;
44-
}
22+
private EntityManagerInterface $entityManager,
23+
private NewsletterRepository $newsletterRepository,
24+
private LoggerInterface $logger
25+
){}
4526

4627
/**
4728
* Find and return a newsletter subscription by email address.

Service/UnsubscribeService.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,14 @@
1010
*/
1111
class UnsubscribeService
1212
{
13-
/**
14-
* @var NewsletterRepository
15-
*/
16-
private $newsletterRepository;
17-
18-
/**
19-
* @var EntityManagerInterface
20-
*/
21-
private $entityManager;
22-
2313
/**
2414
* @param NewsletterRepository $newsletterRepository
2515
* @param EntityManagerInterface $entityManager
2616
*/
2717
public function __construct(
28-
NewsletterRepository $newsletterRepository,
29-
EntityManagerInterface $entityManager
30-
) {
31-
$this->newsletterRepository = $newsletterRepository;
32-
$this->entityManager = $entityManager;
33-
}
18+
private NewsletterRepository $newsletterRepository,
19+
private EntityManagerInterface $entityManager
20+
){}
3421

3522
/**
3623
* Remove a newsletter subscription by a given token.

0 commit comments

Comments
 (0)