1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the MilioooMessageBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Michiel boeckaert <[email protected]> |
7
|
|
|
* This source file is subject to the MIT license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Miliooo\Messaging\Specifications; |
12
|
|
|
|
13
|
|
|
use Miliooo\Messaging\User\ParticipantInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* This specification is responsible for deciding if a given user can send a message to a given recipient. |
17
|
|
|
* |
18
|
|
|
* The default implementation is to just return true. |
19
|
|
|
* |
20
|
|
|
* @author Michiel Boeckaert <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
interface CanMessageRecipientInterface |
23
|
|
|
{ |
24
|
|
|
CONST ERROR_RECIPIENT_BANNED = 'validate.recipient_banned'; |
|
|
|
|
25
|
|
|
CONST ERROR_RECIPIENT_BLOCKED_SENDER = 'validate.recipient_blocked_sender'; |
|
|
|
|
26
|
|
|
CONST ERROR_RECIPIENT_INACTIVE = 'validate_recipient_no_longer_active'; |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Decides whether the current participant can send a message to the given recipient. |
30
|
|
|
* |
31
|
|
|
* @param ParticipantInterface $currentParticipant The current participant |
32
|
|
|
* @param ParticipantInterface $recipient The recipient |
33
|
|
|
* |
34
|
|
|
* @return boolean true if the participant can send a message to the recipient, false otherwise |
35
|
|
|
*/ |
36
|
|
|
public function isSatisfiedBy(ParticipantInterface $currentParticipant, ParticipantInterface $recipient); |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Returns an error message when isSatisfiedBy returns false. |
40
|
|
|
* |
41
|
|
|
* This function makes it possible to return a custom error message for the canMessageRecipientValidator. |
42
|
|
|
* |
43
|
|
|
* There can be many reasons why you can't message a recipient. |
44
|
|
|
* Since the validator wants to output a correct message why you can't send a message to someone it needs |
45
|
|
|
* this information. |
46
|
|
|
* |
47
|
|
|
* To make it possible to translate those reasons we return a placeholder that gets translated in |
48
|
|
|
* validation.{language}.yml. For this we use one of the constants. |
49
|
|
|
* |
50
|
|
|
* If there are more generic constants that needs to be add you can do a pull request for this. |
51
|
|
|
* That way we can update the constants and the translations. |
52
|
|
|
* |
53
|
|
|
* @return string|null An error message when isSatisfiedBy returns false, or null otherwise. |
54
|
|
|
*/ |
55
|
|
|
public function getErrorMessage(); |
56
|
|
|
} |
57
|
|
|
|