Skip to content

Commit 7e861d2

Browse files
committed
Add superficial persistence
1 parent 84f571b commit 7e861d2

File tree

10 files changed

+190
-3
lines changed

10 files changed

+190
-3
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 Omines Internetbureau
3+
Copyright (c) 2025 Omines Internetbureau B.V.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
"require": {
1818
"php": ">=8.2",
1919
"ext-mbstring": "*",
20+
"doctrine/orm": "^2.20.1|^3.3.1",
2021
"omines/antispam-bundle": "^0.1.10",
2122
"symfony/form": "^6.4|^7.1",
2223
"symfony/framework-bundle": "^6.4|^7.1",
2324
"symfony/translation": "^6.4|^7.1",
2425
"symfony/twig-bridge": "^6.4|^7.1"
2526
},
2627
"require-dev": {
28+
"ext-sqlite3": "*",
29+
"doctrine/doctrine-bundle": "^2.13",
2730
"ekino/phpstan-banned-code": "^3.0",
2831
"friendsofphp/php-cs-fixer": "^3.68.0",
2932
"infection/infection": "^0.29.8",

config/services.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
_defaults:
3+
autowire: true # Automatically injects dependencies in your services.
4+
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
5+
6+
_instanceof:
7+
Psr\Log\LoggerAwareInterface:
8+
tags:
9+
- name: monolog.logger
10+
channel: 'antispam'
11+
12+
Omines\AntiSpamQuarantineBundle\:
13+
resource: '../src'

src/DependencyInjection/QuarantineExtension.php

+26-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,38 @@
1313
namespace Omines\AntiSpamQuarantineBundle\DependencyInjection;
1414

1515
use Omines\AntiSpamQuarantineBundle\AntiSpamQuarantineBundle;
16+
use Symfony\Component\Config\FileLocator;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Extension\Extension;
19+
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
20+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
1821

19-
class QuarantineExtension extends Extension
22+
class QuarantineExtension extends Extension implements PrependExtensionInterface
2023
{
2124
public function load(array $configs, ContainerBuilder $container): void
2225
{
23-
// TODO: Implement load() method.
26+
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
27+
$loader->load('services.yaml');
28+
}
29+
30+
public function prepend(ContainerBuilder $container): void
31+
{
32+
if ($container->hasExtension('doctrine')) {
33+
$container->prependExtensionConfig('doctrine', [
34+
'orm' => [
35+
'mappings' => [
36+
'QuarantineBundle' => [
37+
'type' => 'attribute',
38+
'dir' => __DIR__ . '/../Entity',
39+
'prefix' => 'Omines\AntiSpamQuarantineBundle\Entity',
40+
'alias' => 'Quarantine',
41+
],
42+
],
43+
],
44+
]);
45+
} else {
46+
throw new \LogicException('DoctrineBundle is required for quarantine bundle to work, please run composer require doctrine/doctrine-bundle');
47+
}
2448
}
2549

2650
public function getAlias(): string

src/Entity/QuarantineEntry.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* Symfony Anti-Spam Quarantine Bundle
5+
* (c) Omines Internetbureau B.V. - https://omines.nl/
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace Omines\AntiSpamQuarantineBundle\Entity;
14+
15+
use Doctrine\ORM\Mapping\Column;
16+
use Doctrine\ORM\Mapping\Entity;
17+
use Doctrine\ORM\Mapping\GeneratedValue;
18+
use Doctrine\ORM\Mapping\Id;
19+
use Omines\AntiSpamQuarantineBundle\Repository\QuarantineEntryRepository;
20+
21+
#[Entity(repositoryClass: QuarantineEntryRepository::class)]
22+
class QuarantineEntry
23+
{
24+
#[Column, Id, GeneratedValue]
25+
public int $id;
26+
27+
#[Column]
28+
public string $hello;
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* Symfony Anti-Spam Quarantine Bundle
5+
* (c) Omines Internetbureau B.V. - https://omines.nl/
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace Omines\AntiSpamQuarantineBundle\Repository;
14+
15+
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
16+
use Doctrine\Persistence\ManagerRegistry;
17+
use Omines\AntiSpamQuarantineBundle\Entity\QuarantineEntry;
18+
19+
/**
20+
* @extends ServiceEntityRepository<QuarantineEntry>
21+
*/
22+
class QuarantineEntryRepository extends ServiceEntityRepository
23+
{
24+
public function __construct(ManagerRegistry $registry)
25+
{
26+
parent::__construct($registry, QuarantineEntry::class);
27+
}
28+
}

tests/Fixture/.env

+2
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
2828
###> symfony/mailer ###
2929
# MAILER_DSN=null://null
3030
###< symfony/mailer ###
31+
32+
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"

tests/Fixture/config/bundles.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
77
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
88
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
9+
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
910
Omines\AntiSpamBundle\AntiSpamBundle::class => ['all' => true],
1011
Omines\AntiSpamQuarantineBundle\AntiSpamQuarantineBundle::class => ['all' => true],
1112
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
doctrine:
2+
dbal:
3+
url: '%env(resolve:DATABASE_URL)%'
4+
5+
# IMPORTANT: You MUST configure your server version,
6+
# either here or in the DATABASE_URL env var (see .env file)
7+
#server_version: '16'
8+
9+
profiling_collect_backtrace: '%kernel.debug%'
10+
use_savepoints: true
11+
orm:
12+
auto_generate_proxy_classes: true
13+
enable_lazy_ghost_objects: true
14+
report_fields_where_declared: true
15+
validate_xml_mapping: true
16+
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
17+
18+
# We disable auto_mapping on purpose to validate we can still inject entities then
19+
auto_mapping: false
20+
mappings:
21+
App:
22+
type: attribute
23+
is_bundle: false
24+
dir: '%kernel.project_dir%/src/Entity'
25+
prefix: 'Tests\Fixture\Entity'
26+
alias: Test
27+
controller_resolver:
28+
auto_mapping: true
29+
30+
when@test:
31+
doctrine:
32+
dbal:
33+
# "TEST_TOKEN" is typically set by ParaTest
34+
dbname_suffix: '_test%env(default::TEST_TOKEN)%'
35+
36+
when@prod:
37+
doctrine:
38+
orm:
39+
auto_generate_proxy_classes: false
40+
proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies'
41+
query_cache_driver:
42+
type: pool
43+
pool: doctrine.system_cache_pool
44+
result_cache_driver:
45+
type: pool
46+
pool: doctrine.result_cache_pool
47+
48+
framework:
49+
cache:
50+
pools:
51+
doctrine.result_cache_pool:
52+
adapter: cache.app
53+
doctrine.system_cache_pool:
54+
adapter: cache.system
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* Symfony Anti-Spam Quarantine Bundle
5+
* (c) Omines Internetbureau B.V. - https://omines.nl/
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace Tests\Fixture\Entity;
14+
15+
use Doctrine\DBAL\Types\Types;
16+
use Doctrine\ORM\Mapping\Column;
17+
use Doctrine\ORM\Mapping\Entity;
18+
use Doctrine\ORM\Mapping\GeneratedValue;
19+
use Doctrine\ORM\Mapping\Id;
20+
use Symfony\Component\Validator\Constraints as Assert;
21+
22+
#[Entity]
23+
class OfferRequest
24+
{
25+
#[Column, Id, GeneratedValue(strategy: 'AUTO')]
26+
public int $id;
27+
28+
#[Column, Assert\NotBlank, Assert\Length(min: 3, max: 50)]
29+
public string $subject;
30+
31+
#[Column(type: Types::TEXT)]
32+
public string $description;
33+
}

0 commit comments

Comments
 (0)