public function testMethodSingletonReturnsAlwaysTheSameInstanceForTheSameStackName() { $notification1 = Horde_Notification::singleton('test'); $notification2 = Horde_Notification::singleton('test'); $this->assertSame($notification1, $notification2); }
/** * Allows other Horde apps to remove messages. * * The forum name is constructed by just the $forum_name variable * under the data root 'agora.forums.<app>'. It is up to the apps * themselves to make sure that the forum name is unique. * * @access private * * @param string $scope The application which is posting this message. * @param string $forum_name The unique name for the forum. * @param string $callback A callback method of the specified application * that gets called to make sure that posting to * this forum is allowed. * @param array $params Any parameters for the forum message posting. * <pre> * message_id - An existing message to delete * </pre> * @param array $variables A hash with all variables of a submitted form * generated by this method. * * @return mixed Returns either the rendered Horde_Form for posting a message * or PEAR_Error object on error, or true in case of a * successful post. */ public function removeMessage($scope, $forum_name, $callback, $params = array(), $variables = null) { global $registry; /* Check if posting messages is allowed. */ $check = $registry->callByPackage($scope, $callback, array($forum_name)); if ($check instanceof PEAR_Error || !$check) { return ''; } /* Create a separate notification queue. */ $queue = Horde_Notification::singleton('agoraRemoveMessage'); $queue->attach('status'); /* Set up the forums object. */ $forums = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope); $params['forum_id'] = $forums->getForumId($forum_name); if (empty($params['forum_id'])) { return PEAR::raiseError(sprintf(_("Forum %s does not exist."), $forum_name)); } /* Set up the messages control object. */ $messages = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope, $params['forum_id']); if ($messages instanceof PEAR_Error) { PEAR::raiseError(sprintf(_("Could not delete the message. %s"), $messages->getMessage())); } /* Check delete permissions. */ if (!$messages->hasPermission(Horde_Perms::DELETE)) { return PEAR::raiseError(sprintf(_("You don't have permission to delete messages in forum %s."), $params['forum_id'])); } /* Get the message to be deleted. */ $message = $messages->getMessage($params['message_id']); if ($message instanceof PEAR_Error) { return PEAR::raiseError(sprintf(_("Could not delete the message. %s"), $message->getMessage())); } /* Set up the form. */ $vars = new Horde_Variables($variables); $form = new Horde_Form($vars, sprintf(_("Delete \"%s\" and all replies?"), $message['message_subject']), 'delete_agora_message'); $form->setButtons(array(_("Delete"), _("Cancel"))); $form->addHidden('', 'forum_id', 'int', true); $form->addHidden('', 'message_id', 'int', true); if ($form->validate()) { if ($vars->get('submitbutton') == _("Delete")) { $result = $messages->deleteMessage($params['message_id']); if ($result instanceof PEAR_Error) { $queue->push(sprintf(_("Could not delete the message. %s"), $result->getMessage()), 'horde.error'); } else { $queue->push(_("Message deleted."), 'horde.success'); $count = $messages->countMessages(); $registry->callByPackage($scope, $callback, array($forum_name, 'messages', $count)); } } else { $queue->push(_("Message not deleted."), 'horde.message'); } Horde::startBuffer(); $queue->notify(array('listeners' => 'status')); return Horde::endBuffer(); } Horde::startBuffer(); $form->renderActive(null, null, null, 'post', null, false); return Horde::endBuffer(); }