Last active
December 1, 2015 10:14
-
-
Save clemgrim/42ff2cdc3ffedc0389ee to your computer and use it in GitHub Desktop.
JMSSerializer provider for Silex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Pimple\Container; | |
use Pimple\ServiceProviderInterface; | |
use JMS\Serializer\SerializerBuilder; | |
use Doctrine\Common\Annotations\AnnotationRegistry; | |
use JMS\Serializer\SerializationContext; | |
class SerializerServiceProvider implements ServiceProviderInterface | |
{ | |
/** | |
* @param Container $app | |
*/ | |
public function register(Container $app) | |
{ | |
$root = realpath($app['path.root'] .'/../'); | |
AnnotationRegistry::registerAutoloadNamespace('JMS\Serializer\Annotation', $root. "/vendor/jms/serializer/src"); | |
$app['serializer'] = function () use ($app) { | |
$serializer = SerializerBuilder::create(); | |
if ($app['debug'] == false) { | |
$serializer->setCacheDir($app['path.app'] . '/../cache'); | |
} | |
return $serializer->build(); | |
}; | |
$app['serializer.context'] = function () { | |
return SerializationContext::create()->enableMaxDepthChecks(); | |
}; | |
} | |
/** | |
* @param Container $app | |
*/ | |
public function boot(Container $app) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment