made the bundle compatible with Elastica 0.20.x
This commit is contained in:
parent
d8f836d179
commit
aafb6e53fb
28 changed files with 161 additions and 125 deletions
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace FOQ\ElasticaBundle\Serializer;
|
||||
namespace FOS\ElasticaBundle\Serializer;
|
||||
|
||||
use JMS\Serializer\SerializationContext;
|
||||
use JMS\Serializer\Serializer;
|
||||
|
||||
class Callback
|
||||
|
|
@ -10,6 +11,8 @@ class Callback
|
|||
|
||||
protected $groups;
|
||||
|
||||
protected $version;
|
||||
|
||||
public function setSerializer($serializer)
|
||||
{
|
||||
$this->serializer = $serializer;
|
||||
|
|
@ -20,14 +23,31 @@ class Callback
|
|||
$this->groups = $groups;
|
||||
}
|
||||
|
||||
public function setVersion($version)
|
||||
{
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
public function serialize($object)
|
||||
{
|
||||
if ($this->serializer instanceof Serializer) {
|
||||
$this->serializer->setGroups($this->groups);
|
||||
} elseif ($this->groups) {
|
||||
throw new \RuntimeException('Setting serialization groups requires using "JMS\Serializer\Serializer"');
|
||||
$context = $this->serializer instanceof Serializer ? new SerializationContext() : null;
|
||||
|
||||
if ($this->groups) {
|
||||
if (!$context) {
|
||||
throw new \RuntimeException('Setting serialization groups requires using "JMS\Serializer\Serializer"');
|
||||
}
|
||||
|
||||
$context->setGroups($this->groups);
|
||||
}
|
||||
|
||||
return $this->serializer->serialize($object, 'json');
|
||||
if ($this->version) {
|
||||
if (!$context) {
|
||||
throw new \RuntimeException('Setting serialization version requires using "JMS\Serializer\Serializer"');
|
||||
}
|
||||
|
||||
$context->setVersion($this->version);
|
||||
}
|
||||
|
||||
return $this->serializer->serialize($object, 'json', $context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue