Browse Source

Fix RegisterEventListenersAndSubscribersPass

Adrien Brault 12 years ago
parent
commit
543fd54501

+ 13 - 7
DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php

@@ -17,12 +17,12 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
                     throw new \RuntimeException(sprintf('The tag "jms_serializer.event_listener" of service "%s" requires an attribute named "event".', $id));
                 }
 
-                $class = isset($attributes['class']) ? $attributes['class'] : null;
+                $class = isset($attributes['class']) ? strtolower($attributes['class']) : null;
                 $format = isset($attributes['format']) ? $attributes['format'] : null;
                 $method = isset($attributes['method']) ? $attributes['method'] : EventDispatcher::getDefaultMethodName($attributes['event']);
                 $priority = isset($attributes['priority']) ? (integer) $attributes['priority'] : 0;
 
-                $listeners[$priority][] = array($attributes['event'], array($id, $method), $class, $format);
+                $listeners[$attributes['event']][$priority][] = array(array($id, $method), $class, $format);
             }
         }
 
@@ -37,20 +37,26 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
                     throw new \RuntimeException(sprintf('The service "%s" (class: %s) must return an event for each subscribed event.', $id, $subscriberClass));
                 }
 
-                $class = isset($eventData['class']) ? $eventData['class'] : null;
+                $class = isset($eventData['class']) ? strtolower($eventData['class']) : null;
                 $format = isset($eventData['format']) ? $eventData['format'] : null;
                 $method = isset($eventData['method']) ? $eventData['method'] : EventDispatcher::getDefaultMethodName($eventData['event']);
-                $priority = isset($attributes['priority']) ? (integer) $attributes['priority'] : 0;
+                $priority = isset($attributes['priority']) ? (integer) $attributes['priority'] : 0;
 
-                $listeners[$priority][] = array($eventData['event'], array($id, $method), $class, $format);
+                $listeners[$eventData['event']][$priority][] = array(array($id, $method), $class, $format);
             }
         }
 
         if ($listeners) {
-            ksort($listeners);
+            array_walk($listeners, function (&$value, $key) {
+                ksort($value);
+            });
+
+            foreach ($listeners as &$events) {
+                $events = call_user_func_array('array_merge', $events);
+            }
 
             $container->getDefinition('jms_serializer.event_dispatcher')
-                ->addMethodCall('setListeners', array(call_user_func_array('array_merge', $listeners)));
+                ->addMethodCall('setListeners', array($listeners));
         }
     }
 }