/**
  * {@inheritDoc}
  */
 public function loadMetadata($class)
 {
     if (is_object($class)) {
         $class = get_class($class);
     }
     $key = 'notifier:' . $class;
     $metadata = $this->cache->get($key);
     if (null === $metadata) {
         $metadata = $this->delegate->loadMetadata($class);
         $this->cache->set($key, $metadata);
     }
     return $metadata;
 }
 /**
  * Add class listens
  *
  * @param string|array $classes
  * @param string       $onEvent
  *
  * @return Builder
  *
  * @throws ClassNotSupportedException
  */
 public function listen($classes, $onEvent = null)
 {
     if (!is_array($classes)) {
         $classes = [$classes];
     }
     foreach ($classes as $class) {
         if (!$this->metadataFactory->supportsClass($class)) {
             throw new ClassNotSupportedException(sprintf('The class "%s" not supports for notification system.', $class));
         }
         $metadata = $this->metadataFactory->loadMetadata($class);
         if ($onEvent) {
             $notifications = [$metadata->getNotificationForEvent($onEvent)];
         } else {
             $notifications = $metadata->getNotifications();
         }
         foreach ($notifications as $notification) {
             $this->listens[$notification->getName()] = $class;
         }
     }
     return $this;
 }
 /**
  * {@inheritDoc}
  */
 public function notify($object, $onEvent = null)
 {
     if (!is_object($object)) {
         throw UnexpectedTypeException::create($object, 'object');
     }
     $notifyClass = get_class($object);
     if (!$this->supportsObject($object)) {
         throw new ClassNotSupportedException(sprintf('The object instance "%s" not supports send notification with event "%s".', $notifyClass, $onEvent ? $onEvent : 'NULL'));
     }
     $classMetadata = $this->metadataFactory->loadMetadata($notifyClass);
     $metadata = $this->getNotificationMetadataForEvent($classMetadata, $onEvent, $notifyClass);
     $notification = $this->createNotification($metadata, $object);
     $this->senderStrategyManager->getStrategy($metadata->getStrategy())->sendNotification($this->sender, $notification);
 }