PHP code example of jdesrosiers / silex-jms-serializer-provider
1. Go to this page and download the library: Download jdesrosiers/silex-jms-serializer-provider library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jdesrosiers / silex-jms-serializer-provider example snippets
$app->register(new JDesrosiers\Silex\Provider\JmsSerializerServiceProvider(), array(
"serializer.srcDir" => __DIR__ . "/vendor/jms/serializer/src",
));
$app->get("/foo", function () use ($app) {
$foo = new Foo();
return $app["serializer"]->serialize($foo, "json");
});
$app->register(new JDesrosiers\Silex\Provider\JmsSerializerServiceProvider(), array(
"serializer.srcDir" => __DIR__ . "/vendor/jms/serializer/src",
// "serializer.namingStrategy" => "IdenticalProperty",
));
$app["serializer.builder"]->setPropertyNamingStrategy(new IdenticalPropertyNamingStrategy());
$closure = Pimple::protect(
function(JMS\Serializer\Handler\HandlerRegistry $registry) {
$registry->registerHandler('serialization', 'MyObject', 'json',
function($visitor, MyObject $obj, array $type) {
return $obj->getName();
}
);
}
);
$app->register(new JDesrosiers\Silex\Provider\JmsSerializerServiceProvider(), array(
"serializer.srcDir" => __DIR__ . "/vendor/jms/serializer/src",
"serializer.configureHandlers" => $closure,
));