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
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
3.10.0 (unreleased):
* Feature: Allow complex types to be handled by symfony/serializer if available
* Feature: Leverage dependency injection for Serializers
* Fix: Profiler tab was broken in some case
* Enhancement: Better looking profiling tab

3.9.0 (2025-01-17):
* Feature: (SF6.2+) Supports automatic value resolving in controllers (with or without MapEntity), see [https://github.com/symfony/symfony/blob/7.2/src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php](Doctrine Bridge)
* Feature: supports serializer options in attributes
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache-2.0",
"require": {
"php": ">=8.1",
"ccmbenchmark/ting": "^3.10",
"ccmbenchmark/ting": "^3.11",
"doctrine/cache": "^1.10",
"symfony/validator": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0 || ^7.0",
Expand All @@ -18,7 +18,9 @@
"atoum/stubs": "^2.2",
"brick/geo": ">=0.5 <=1.0",
"symfony/expression-language": "^6.3 || ^7.2",
"symfony/serializer": "^6.0 || ^7.0",
"symfony/security-bundle": "^6.0 || ^7.0",
"symfony/security-core": "^6.0 || ^7.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fun story: security-bundle@6.0 requires security-core ^5.4 | ^6.0 ; tests were perfectly fine when I added the User provider, even with lowest deps.
But it should not have been this way: the interface for the UserProvider was different in security-core 5.4 (loadByUsername became loadByIdentifier in 6.0). Tests were green even with security-core 5.4 ; but not anymore. So we lock the core at 6.0 minimum to avoid that.

"symfony/uid": "^6.0 || ^7.0"
},
"autoload": {
Expand Down
6 changes: 2 additions & 4 deletions src/TingBundle/DataCollector/TingCacheDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class TingCacheDataCollector extends DataCollector implements LateDataCollectorI
*/
protected $cacheLogger = null;

protected array|Data $data = [];

public function __construct()
{
$this->init();
Expand All @@ -57,7 +55,7 @@ public function __construct()
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
{
if ($this->cacheLogger !== null) {
$this->data['cache']['operations'] = $this->cacheLogger->getOperations();
$this->data['cache']['operations'] = $this->cloneVar($this->cacheLogger->getOperations());
$this->data['cache']['operationsCount'] = count($this->data['cache']['operations']);
$this->data['cache']['time'] = $this->cacheLogger->getTotalTime();
$this->data['cache']['hits'] = $this->cacheLogger->getHits();
Expand All @@ -68,7 +66,7 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
public function lateCollect(): void
{
if ($this->cacheLogger !== null) {
$this->data['cache']['operations'] = $this->cacheLogger->getOperations();
$this->data['cache']['operations'] = $this->cloneVar($this->cacheLogger->getOperations());
$this->data['cache']['operationsCount'] = count($this->data['cache']['operations']);
$this->data['cache']['time'] = $this->cacheLogger->getTotalTime();
$this->data['cache']['hits'] = $this->cacheLogger->getHits();
Expand Down
38 changes: 8 additions & 30 deletions src/TingBundle/DataCollector/TingDriverDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class TingDriverDataCollector extends DataCollector implements LateDataCollector
*/
protected $driverLogger = null;

protected array|Data $data = [];

public function __construct()
{
$this->init();
Expand All @@ -57,44 +55,24 @@ public function __construct()
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
{
if ($this->driverLogger !== null) {
$this->data['driver']['queries'] = $this->driverLogger->getQueries();
$this->data['driver']['execs'] = $this->driverLogger->getExecs();
$this->data['driver']['queries'] = $this->cloneVar($this->driverLogger->getQueries());
$this->data['driver']['execs'] = $this->cloneVar($this->driverLogger->getExecs());
$this->data['driver']['queryCount'] = count($this->data['driver']['queries']);
$this->data['driver']['time'] = $this->driverLogger->getTotalTime();
$this->data['driver']['connections'] = $this->driverLogger->getConnections();
$this->data['driver']['connectionsHashToName'] = $this->driverLogger->getConnectionsHashToName();

// HttpKernel < 3.2 compatibility layer
// For >= 3.2 cloneVar is always present and MUST be used.
if (method_exists($this, 'cloneVar')) {
foreach ($this->data['driver']['queries'] as &$query) {
if (isset($query['params']) === true) {
$query['params'] = $this->cloneVar($query['params']);
}
}
}
$this->data['driver']['connections'] = $this->cloneVar($this->driverLogger->getConnections());
$this->data['driver']['connectionsHashToName'] = $this->cloneVar($this->driverLogger->getConnectionsHashToName());
}
}

public function lateCollect(): void
{
if ($this->driverLogger !== null) {
$this->data['driver']['queries'] = $this->driverLogger->getQueries();
$this->data['driver']['execs'] = $this->driverLogger->getExecs();
$this->data['driver']['queries'] = $this->cloneVar($this->driverLogger->getQueries());
$this->data['driver']['execs'] = $this->cloneVar($this->driverLogger->getExecs());
$this->data['driver']['queryCount'] = count($this->data['driver']['queries']);
$this->data['driver']['time'] = $this->driverLogger->getTotalTime();
$this->data['driver']['connections'] = $this->driverLogger->getConnections();
$this->data['driver']['connectionsHashToName'] = $this->driverLogger->getConnectionsHashToName();

// HttpKernel < 3.2 compatibility layer
// For >= 3.2 cloneVar is always present and MUST be used.
if (method_exists($this, 'cloneVar')) {
foreach ($this->data['driver']['queries'] as &$query) {
if (isset($query['params']) === true) {
$query['params'] = $this->cloneVar($query['params']);
}
}
}
$this->data['driver']['connections'] = $this->cloneVar($this->driverLogger->getConnections());
$this->data['driver']['connectionsHashToName'] = $this->cloneVar($this->driverLogger->getConnectionsHashToName());
}
}

Expand Down
22 changes: 19 additions & 3 deletions src/TingBundle/DependencyInjection/TingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use CCMBenchmark\TingBundle\ArgumentResolver\EntityValueResolver;
use CCMBenchmark\TingBundle\Schema\Column;
use CCMBenchmark\TingBundle\Schema\Table;
use CCMBenchmark\TingBundle\Serializer\SymfonySerializer;
use Doctrine\Common\Cache\VoidCache;
use Symfony\Component\DependencyInjection\ChildDefinition;
use CCMBenchmark\TingBundle\TingBundle;
Expand All @@ -43,6 +44,7 @@
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\PropertyAccess\PropertyAccessor;

Expand Down Expand Up @@ -152,6 +154,11 @@ public function load(array $configs, ContainerBuilder $container): void

$container->setDefinition(EntityValueResolver::class, $definition);
}

$serializerFactoryDefinition = $container->getDefinition('ting.serializerfactory');
foreach ($container->findTaggedServiceIds('ting.serializer') as $id => $tags) {
$serializerFactoryDefinition->addMethodCall('add', [new Reference($id)]);
}
}

/**
Expand Down Expand Up @@ -205,15 +212,24 @@ function getMetadata(\ReflectionClass $reflector, Table $attribute): Definition
\DateTime::class => 'datetime',
\DateTimeZone::class => 'datetimezone',
Uuid::class => 'uuid',
default => 'string'
default => (interface_exists(SerializerInterface::class) ? 'symfony_serializer' : 'string')
};
}
$options = $mappingAttribute->getArguments()['serializerOptions'] ?? [];
if ($newField['type'] === 'symfony_serializer') {
$defaultOptions = [
'serialize' => ['context' => ['groups' => ['*']]],
'unserialize' => ['context' => ['groups' => ['*']], 'type' => $property->getType()->getName()]
];
$options = array_merge_recursive($defaultOptions, $options);
$newField['serializer'] = SymfonySerializer::class;
}

if ($mappingAttribute->getArguments()['serializer'] ?? false) {
$newField['serializer'] = $mappingAttribute->getArguments()['serializer'];
}
if ($mappingAttribute->getArguments()['serializerOptions'] ?? false) {
$newField['serializer_options'] = $mappingAttribute->getArguments()['serializerOptions'];
if ($options !== []) {
$newField['serializer_options'] = $options;
}

$newMetadata->addMethodCall('addField', [$newField]);
Expand Down
33 changes: 32 additions & 1 deletion src/TingBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<instanceof id="CCMBenchmark\Ting\Serializer\SerializerInterface" autowire="true">
<!-- Auto tag all instances of SerializerInterface with "ting.serializer" -->
<tag name="ting.serializer" />
</instanceof>

<service id="ting" class="CCMBenchmark\TingBundle\Repository\RepositoryFactory" public="true">
<argument type="service" id="ting.connectionpool" />
<argument type="service" id="ting.metadatarepository" />
Expand All @@ -28,7 +33,7 @@
</service>
<service id="CCMBenchmark\Ting\MetadataRepository" alias="ting.metadatarepository" />

<service id="ting.serializerfactory" class="CCMBenchmark\Ting\Serializer\SerializerFactory" public="true">
<service id="ting.serializerfactory" class="CCMBenchmark\TingBundle\Serializer\SerializerFactory" public="true">
</service>
<service id="CCMBenchmark\Ting\Serializer\SerializerFactoryInterface" alias="ting.serializerfactory" />

Expand Down Expand Up @@ -118,5 +123,31 @@
<argument type="service" id="ting" />
<argument type="service" id="Symfony\Component\ExpressionLanguage\ExpressionLanguage" on-invalid="null" />
</service>

<service id="CCMBenchmark\Ting\Serializer\Json" >
<tag name="ting.serializer" />
</service>
<service id="CCMBenchmark\Ting\Serializer\BackedEnum" >
<tag name="ting.serializer" />
</service>
<service id="CCMBenchmark\Ting\Serializer\DateTime" >
<tag name="ting.serializer" />
</service>
<service id="CCMBenchmark\Ting\Serializer\DateTimeImmutable" >
<tag name="ting.serializer" />
</service>
<service id="CCMBenchmark\Ting\Serializer\DateTimeZone" >
<tag name="ting.serializer" />
</service>
<service id="CCMBenchmark\Ting\Serializer\Geometry" >
<tag name="ting.serializer" />
</service>
<service id="CCMBenchmark\Ting\Serializer\Uuid" >
<tag name="ting.serializer" />
</service>
<service id="CCMBenchmark\TingBundle\Serializer\SymfonySerializer" >
<argument id="Symfony\Component\Serializer\SerializerInterface" on-invalid="null" />
<tag name="ting.serializer" />
</service>
</services>
</container>
Loading