* @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ class SimpleObjectHydrator extends BaseSimpleObjectHydrator { /** * State of skipOnLoad for listener between hydrations * * @see SimpleObjectHydrator::prepare() * @see SimpleObjectHydrator::cleanup() * * @var bool */ private $savedSkipOnLoad; /** * {@inheritdoc} */ protected function prepare() { $listener = $this->getTranslatableListener(); $this->savedSkipOnLoad = $listener->isSkipOnLoad(); $listener->setSkipOnLoad(true); parent::prepare(); } /** * {@inheritdoc} */ protected function cleanup() { parent::cleanup(); $listener = $this->getTranslatableListener(); $listener->setSkipOnLoad($this->savedSkipOnLoad !== null ? $this->savedSkipOnLoad : false); } /** * Get the currently used TranslatableListener * * @throws \Gedmo\Exception\RuntimeException - if listener is not found * * @return TranslatableListener */ protected function getTranslatableListener() { $translatableListener = null; foreach ($this->_em->getEventManager()->getListeners() as $event => $listeners) { foreach ($listeners as $hash => $listener) { if ($listener instanceof TranslatableListener) { $translatableListener = $listener; break; } } if ($translatableListener) { break; } } if (is_null($translatableListener)) { throw new \Gedmo\Exception\RuntimeException('The translation listener could not be found'); } return $translatableListener; } }