Beispiel #1
0
 public function setHandlers($handlers)
 {
     if (!is_array($handlers)) {
         $handlers = [$handlers];
     }
     $fullyQualifiedHandlerNames = [];
     foreach ($handlers as $handler) {
         if (is_string($handler)) {
             $handler = $this->handlerResolver->resolve($handler);
         }
         if (!$handler instanceof HandlerInterface) {
             throw new HandlerNotFound('Must provide either a handler name or handler object.');
         }
         $fullyQualifiedHandlerNames[] = $handler->getFullyQualifiedName();
     }
     $this->handlers = $fullyQualifiedHandlerNames;
     return $this;
 }
 public function getMessage($name, array $templateValues)
 {
     if (!array_key_exists($name, $this->anonymousMessages)) {
         throw new TemplateNotFound("Message template not found with name '{$name}'.");
     }
     $user = $this->user;
     if (!$user && Pimple::hasResource('user')) {
         $user = Pimple::getResource('user');
     }
     $userHandler = null;
     try {
         $userHandler = $this->handlerResolver->resolve('user');
     } catch (HandlerNotFound $e) {
         // OK to proceed without the user handler.  Will just treat as anonymous.
     }
     if (!$user || !$userHandler) {
         $template = $this->anonymousMessages[$name];
     } else {
         $template = $this->userMessages[$name];
         // Automatically include %user% value when available.
         $templateValues['%user%'] = $userHandler->createEntity($user->getId());
     }
     return $this->renderTemplateTags($template, $templateValues);
 }
Beispiel #3
0
 /**
  * @param string $fullyQualifiedName
  * @return HandlerInterface
  * @throws ActivityLog\Exception\HandlerNotFound
  */
 public function handlerByFullyQualifiedName($fullyQualifiedName)
 {
     $handler = $this->handlerResolver->resolveByFullyQualifiedName($fullyQualifiedName);
     $handler->setActivityLog($this);
     return $handler;
 }