jdesrosiers / silex-jms-serializer-provider Goto Github PK
View Code? Open in Web Editor NEWA silex service provider that integrates JMS Serializer into silex
License: MIT License
A silex service provider that integrates JMS Serializer into silex
License: MIT License
I wonder how i can add a custom Visitor that extends the JsonDeserializationVisitor
. The constructor of JsonDeserializationVisitor
requires an instance of PropertyNamingStrategyInterface
, but i can't access it within the configuration because 'serializer.namingStrategy' is not added to Pimple if it is not defined as an configuration option.
$app->register(new JmsSerializerServiceProvider(), [
// 'serializer.namingStrategy' => new CamelCaseNamingStrategy(),
'serializer.deserializationVisitors' => [
'json' => new StrictJsonDeserializationVisitor($app['serializer.namingStrategy']), // fails, key is missing
]
]);
The example above works if i set the naming strategy and overwrite the default one, but it fails if i don't set it, because 'serializer.namingStrategy' will never be set.
Looking at the source of SerializerBuilder
it is inteded by JMS, that addDefaultSerializationVisitors()
is only called if no custom serializationVisitors are registered, to be able to have none of the default serialization visitors to be added.
This means the default behavior of the builder is, that it only registers defaults if no other visitors are registered first. But JmsSerializerServiceProvider
calls addDefaultSerializationVisitors()
within setSerializationVisitors
. Same goes for DeserializationVisitors.
// JmsSerializerServiceProvider.php
protected function setSerializationVisitors(Container $app, SerializerBuilder $serializerBuilder)
{
// Adds defaults, even if visitors are defined by the config
$serializerBuilder->addDefaultSerializationVisitors();
foreach ($app["serializer.serializationVisitors"] as $format => $visitor) {
$serializerBuilder->setSerializationVisitor($format, $visitor);
}
}
// SerializerBuilder.php->build()
if ( ! $this->visitorsAdded) { // Avoids adding defaults if visitors are added manually.
$this->addDefaultSerializationVisitors();
$this->addDefaultDeserializationVisitors();
}
The solution would be to remove the call to addDefaultSerializationVisitors()
. It is done anyway by the builder if no visitors are defined.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.