1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Neo\EarlyAccess\SubscriptionServices; |
4
|
|
|
|
5
|
|
|
use Neo\EarlyAccess\Subscriber; |
6
|
|
|
use Neo\EarlyAccess\Contracts\Subscription\SubscriptionProvider; |
7
|
|
|
use Neo\EarlyAccess\Contracts\Subscription\SubscriptionRepository; |
8
|
|
|
|
9
|
|
|
class DatabaseService implements SubscriptionProvider |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var \Neo\EarlyAccess\Contracts\Subscription\SubscriptionRepository |
13
|
|
|
*/ |
14
|
|
|
protected $repository; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* DatabaseSubscriptionService constructor. |
18
|
|
|
* |
19
|
|
|
* @param \Neo\EarlyAccess\Contracts\Subscription\SubscriptionRepository $repository |
20
|
|
|
*/ |
21
|
|
|
public function __construct(SubscriptionRepository $repository) |
22
|
|
|
{ |
23
|
|
|
$this->repository = $repository; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Adds a new email to the subscribers list. |
28
|
|
|
* |
29
|
|
|
* @param string $email |
30
|
|
|
* @param string|null $name |
31
|
|
|
* @return bool |
32
|
|
|
*/ |
33
|
|
|
public function add(string $email, string $name = null): bool |
34
|
|
|
{ |
35
|
|
|
return (bool) $this->repository->addSubscriber($email, $name); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Removes an email from the subscribers list. |
40
|
|
|
* |
41
|
|
|
* @param string $email |
42
|
|
|
* @return bool |
43
|
|
|
*/ |
44
|
|
|
public function remove(string $email): bool |
45
|
|
|
{ |
46
|
|
|
return $this->repository->removeSubscriber($email); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Verifies a subscribers email address. |
51
|
|
|
* |
52
|
|
|
* @param string $email |
53
|
|
|
* @return bool |
54
|
|
|
*/ |
55
|
|
|
public function verify(string $email): bool |
56
|
|
|
{ |
57
|
|
|
return $this->repository->verify($email); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Find a subscriber using their email address. |
62
|
|
|
* |
63
|
|
|
* @param string $email |
64
|
|
|
* @return \Neo\EarlyAccess\Subscriber|false |
65
|
|
|
*/ |
66
|
|
|
public function findByEmail(string $email) |
67
|
|
|
{ |
68
|
|
|
return with($this->repository->findByEmail($email), function ($user) { |
69
|
|
|
return $user ? Subscriber::make($user) : false; |
70
|
|
|
}); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|