/
ConfigureNotificationTypes.php
55 lines (46 loc) · 1.29 KB
/
ConfigureNotificationTypes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Event;
use Flarum\Notification\Blueprint\BlueprintInterface;
use InvalidArgumentException;
use ReflectionClass;
class ConfigureNotificationTypes
{
/**
* @var array
*/
private $blueprints;
/**
* @var array
*/
private $serializers;
/**
* @param array $blueprints
* @param array $serializers
*/
public function __construct(array &$blueprints, array &$serializers = [])
{
$this->blueprints = &$blueprints;
$this->serializers = &$serializers;
}
/**
* @param string $blueprint
* @param string $serializer
* @param array $enabledByDefault
*/
public function add($blueprint, $serializer, $enabledByDefault = [])
{
if (! (new ReflectionClass($blueprint))->implementsInterface(BlueprintInterface::class)) {
throw new InvalidArgumentException(
'Notification blueprint '.$blueprint.' must implement '.BlueprintInterface::class
);
}
$this->blueprints[$blueprint] = $enabledByDefault;
$this->serializers[$blueprint::getType()] = $serializer;
}
}