php - How to handle edge case for a subscriber to not act on a specific object using the JMS/Serializer library? -


i using jms/serialzier library.

i have setup event-subscriber, listens events::pre_serialize , convert object instances of class price having property currency , amount different currencies.

public function onpreserialize(preserializeevent $event) {     $object = $event->getobject();     $class = get_class($object);      switch ($class) {         case price::class:             return $this->currencyservice->convertprice($object);     } } 

yet now, in application have edge case 1 price belonging 1 container object edgecase not need converted @ all:

use jms\serializer\annotation\type; class edgecase {      /**      * @type("kopernikus\price")      * @var price      */     private $price; // 1 instance should not handled event subscriber } 

but has retain original state. yet don't seem able differentiate origin of object comming from.

i want able configure price objects should converted , when.

as quick , dirty solution have created staticprice class extending price , changed instantiaton of price object edge case.

i have added further check in subscriber, relevant subscriber looks like:

    switch ($class) {         case price::class:             if ($object instanceof staticprice) {                  break;             }             return $this->currencyservice->convertprice($object);     } 

yet feels wrong solve in such hard-coded way on object level; , have change logic creating price objects. works now.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -