1313
1414namespace Brainbits \Blocking ;
1515
16- use Brainbits \Blocking \Storage \StorageInterface ;
1716use Brainbits \Blocking \Exception \BlockFailedException ;
18- use Brainbits \Blocking \Identifier \IdentifierInterface ;
19- use Brainbits \Blocking \Owner \OwnerInterface ;
17+ use Brainbits \Blocking \Identity \IdentityInterface ;
18+ use Brainbits \Blocking \Owner \OwnerFactoryInterface ;
19+ use Brainbits \Blocking \Storage \StorageInterface ;
2020use Brainbits \Blocking \Validator \ValidatorInterface ;
2121use DateTimeImmutable ;
2222
2626class Blocker
2727{
2828 private $ storage ;
29- private $ owner ;
29+ private $ ownerFactory ;
3030 private $ validator ;
3131
32- public function __construct (StorageInterface $ adapter , OwnerInterface $ owner , ValidatorInterface $ validator )
32+ public function __construct (StorageInterface $ adapter , OwnerFactoryInterface $ ownerFactory , ValidatorInterface $ validator )
3333 {
3434 $ this ->storage = $ adapter ;
35- $ this ->owner = $ owner ;
35+ $ this ->ownerFactory = $ ownerFactory ;
3636 $ this ->validator = $ validator ;
3737 }
3838
39- public function block (IdentifierInterface $ identifier ): BlockInterface
39+ public function block (IdentityInterface $ identifier ): BlockInterface
4040 {
4141 $ block = $ this ->tryBlock ($ identifier );
4242
@@ -47,27 +47,28 @@ public function block(IdentifierInterface $identifier): BlockInterface
4747 return $ block ;
4848 }
4949
50- public function tryBlock (IdentifierInterface $ identifier ): ?BlockInterface
50+ public function tryBlock (IdentityInterface $ identifier ): ?BlockInterface
5151 {
52+ $ owner = $ this ->ownerFactory ->createOwner ();
53+
5254 if ($ this ->isBlocked ($ identifier )) {
5355 $ block = $ this ->getBlock ($ identifier );
54- if (!$ block ->isOwnedBy ($ this -> owner )) {
56+ if (!$ block ->isOwnedBy ($ owner )) {
5557 return null ;
5658 }
5759 $ this ->storage ->touch ($ block );
5860
5961 return $ block ;
6062 }
6163
62- $ block = new Block ($ identifier , $ this -> owner , new DateTimeImmutable ());
64+ $ block = new Block ($ identifier , $ owner , new DateTimeImmutable ());
6365
6466 $ this ->storage ->write ($ block );
6567
6668 return $ block ;
6769 }
6870
69-
70- public function unblock (IdentifierInterface $ identifier ): ?BlockInterface
71+ public function unblock (IdentityInterface $ identifier ): ?BlockInterface
7172 {
7273 $ block = $ this ->getBlock ($ identifier );
7374 if (null === $ block ) {
@@ -79,7 +80,7 @@ public function unblock(IdentifierInterface $identifier): ?BlockInterface
7980 return $ block ;
8081 }
8182
82- public function isBlocked (IdentifierInterface $ identifier ): bool
83+ public function isBlocked (IdentityInterface $ identifier ): bool
8384 {
8485 $ exists = $ this ->storage ->exists ($ identifier );
8586
@@ -99,7 +100,7 @@ public function isBlocked(IdentifierInterface $identifier): bool
99100 return false ;
100101 }
101102
102- public function getBlock (IdentifierInterface $ identifier ): ?BlockInterface
103+ public function getBlock (IdentityInterface $ identifier ): ?BlockInterface
103104 {
104105 if (!$ this ->isBlocked ($ identifier )) {
105106 return null ;
0 commit comments