-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
For more details see #217 Co-authored-by: Paweł Niedzielski <Steveb-p@users.noreply.github.com> Co-authored-by: Nattfarinn <Nattfarinn@users.noreply.github.com> Co-authored-by: Andrew Longosz <alongosz@users.noreply.github.com>
- Loading branch information
1 parent
a14007e
commit 8f1a3c3
Showing
42 changed files
with
2,241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Core\Persistence\Token; | ||
|
||
use Ibexa\Contracts\Core\Persistence\ValueObject; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CreateStruct extends ValueObject | ||
{ | ||
public string $type; | ||
|
||
public string $token; | ||
|
||
public int $ttl; | ||
|
||
public ?string $identifier = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Core\Persistence\Token; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface Handler | ||
{ | ||
/** | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException | ||
*/ | ||
public function getToken( | ||
string $tokenType, | ||
string $token, | ||
?string $identifier = null | ||
): Token; | ||
|
||
public function getTokenType( | ||
string $identifier | ||
): TokenType; | ||
|
||
public function createToken(CreateStruct $createStruct): Token; | ||
|
||
public function deleteToken(Token $token): void; | ||
|
||
public function deleteTokenById(int $tokenId): void; | ||
|
||
public function deleteExpiredTokens(?string $tokenType = null): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Core\Persistence\Token; | ||
|
||
use Ibexa\Contracts\Core\Persistence\ValueObject; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class Token extends ValueObject | ||
{ | ||
public int $id; | ||
|
||
public int $typeId; | ||
|
||
public string $token; | ||
|
||
public ?string $identifier = null; | ||
|
||
public int $created; | ||
|
||
public int $expires; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Core\Persistence\Token; | ||
|
||
use Ibexa\Contracts\Core\Persistence\ValueObject; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class TokenType extends ValueObject | ||
{ | ||
public int $id; | ||
|
||
public string $identifier; | ||
} |
69 changes: 69 additions & 0 deletions
69
src/contracts/Repository/Decorator/TokenServiceDecorator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Core\Repository\Decorator; | ||
|
||
use Ibexa\Contracts\Core\Repository\TokenService; | ||
use Ibexa\Contracts\Core\Repository\Values\Token\Token; | ||
use Ibexa\Contracts\Core\Token\TokenGeneratorInterface; | ||
|
||
abstract class TokenServiceDecorator implements TokenService | ||
{ | ||
protected TokenService $innerService; | ||
|
||
public function __construct( | ||
TokenService $innerService | ||
) { | ||
$this->innerService = $innerService; | ||
} | ||
|
||
public function getToken( | ||
string $tokenType, | ||
string $token, | ||
?string $identifier = null | ||
): Token { | ||
return $this->innerService->getToken( | ||
$tokenType, | ||
$token, | ||
$identifier | ||
); | ||
} | ||
|
||
public function checkToken( | ||
string $tokenType, | ||
string $token, | ||
?string $identifier = null | ||
): bool { | ||
return $this->innerService->checkToken( | ||
$tokenType, | ||
$token, | ||
$identifier | ||
); | ||
} | ||
|
||
public function generateToken( | ||
string $type, | ||
int $ttl, | ||
?string $identifier = null, | ||
int $tokenLength = 64, | ||
?TokenGeneratorInterface $tokenGenerator = null | ||
): Token { | ||
return $this->innerService->generateToken( | ||
$type, | ||
$ttl, | ||
$identifier, | ||
$tokenLength, | ||
$tokenGenerator | ||
); | ||
} | ||
|
||
public function deleteToken(Token $token): void | ||
{ | ||
$this->innerService->deleteToken($token); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/contracts/Repository/Events/Token/BeforeCheckTokenEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Core\Repository\Events\Token; | ||
|
||
use Ibexa\Contracts\Core\Repository\Event\BeforeEvent; | ||
use UnexpectedValueException; | ||
|
||
final class BeforeCheckTokenEvent extends BeforeEvent | ||
{ | ||
private ?bool $result = null; | ||
|
||
private string $tokenType; | ||
|
||
private string $token; | ||
|
||
private ?string $identifier; | ||
|
||
public function __construct( | ||
string $tokenType, | ||
string $token, | ||
?string $identifier = null | ||
) { | ||
$this->tokenType = $tokenType; | ||
$this->token = $token; | ||
$this->identifier = $identifier; | ||
} | ||
|
||
public function getResult(): bool | ||
{ | ||
if (!$this->hasResult()) { | ||
throw new UnexpectedValueException( | ||
'Return value is not set.' . PHP_EOL | ||
. 'Check hasResult() or set it using setResult() before you call the getter.' | ||
); | ||
} | ||
|
||
return $this->result; | ||
} | ||
|
||
public function setResult(?bool $result): void | ||
{ | ||
$this->result = $result; | ||
} | ||
|
||
public function hasResult(): bool | ||
{ | ||
return $this->result !== null; | ||
} | ||
|
||
public function getTokenType(): string | ||
{ | ||
return $this->tokenType; | ||
} | ||
|
||
public function getToken(): string | ||
{ | ||
return $this->token; | ||
} | ||
|
||
public function getIdentifier(): ?string | ||
{ | ||
return $this->identifier; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/contracts/Repository/Events/Token/BeforeDeleteTokenEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Core\Repository\Events\Token; | ||
|
||
use Ibexa\Contracts\Core\Repository\Event\BeforeEvent; | ||
use Ibexa\Contracts\Core\Repository\Values\Token\Token; | ||
|
||
final class BeforeDeleteTokenEvent extends BeforeEvent | ||
{ | ||
private Token $token; | ||
|
||
public function __construct(Token $token) | ||
{ | ||
$this->token = $token; | ||
} | ||
|
||
public function getToken(): Token | ||
{ | ||
return $this->token; | ||
} | ||
} |
Oops, something went wrong.