1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2019 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Jose\Bundle\JoseFramework\Services; |
15
|
|
|
|
16
|
|
|
use Jose\Bundle\JoseFramework\Event\JWELoadingFailureEvent; |
17
|
|
|
use Jose\Bundle\JoseFramework\Event\JWELoadingSuccessEvent; |
18
|
|
|
use Jose\Component\Checker\HeaderCheckerManager; |
|
|
|
|
19
|
|
|
use Jose\Component\Core\JWKSet; |
20
|
|
|
use Jose\Component\Encryption\JWE; |
21
|
|
|
use Jose\Component\Encryption\JWEDecrypter; |
|
|
|
|
22
|
|
|
use Jose\Component\Encryption\JWELoader as BaseJWELoader; |
23
|
|
|
use Jose\Component\Encryption\Serializer\JWESerializerManager; |
24
|
|
|
use Psr\EventDispatcher\EventDispatcherInterface; |
25
|
|
|
use Throwable; |
26
|
|
|
|
27
|
|
|
final class JWELoader extends BaseJWELoader |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var EventDispatcherInterface |
31
|
|
|
*/ |
32
|
|
|
private $eventDispatcher; |
33
|
|
|
|
34
|
|
|
public function __construct(JWESerializerManager $serializerManager, JWEDecrypter $jweDecrypter, ?HeaderCheckerManager $headerCheckerManager, EventDispatcherInterface $eventDispatcher) |
35
|
|
|
{ |
36
|
|
|
parent::__construct($serializerManager, $jweDecrypter, $headerCheckerManager); |
37
|
|
|
$this->eventDispatcher = $eventDispatcher; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function loadAndDecryptWithKeySet(string $token, JWKSet $keyset, ?int &$recipient): JWE |
41
|
|
|
{ |
42
|
|
|
try { |
43
|
|
|
$jwe = parent::loadAndDecryptWithKeySet($token, $keyset, $recipient); |
44
|
|
|
$this->eventDispatcher->dispatch(new JWELoadingSuccessEvent( |
|
|
|
|
45
|
|
|
$token, |
46
|
|
|
$jwe, |
47
|
|
|
$keyset, |
48
|
|
|
$recipient |
49
|
|
|
)); |
50
|
|
|
|
51
|
|
|
return $jwe; |
52
|
|
|
} catch (Throwable $throwable) { |
53
|
|
|
$this->eventDispatcher->dispatch(new JWELoadingFailureEvent( |
|
|
|
|
54
|
|
|
$token, |
55
|
|
|
$keyset, |
56
|
|
|
$throwable |
57
|
|
|
)); |
58
|
|
|
|
59
|
|
|
throw $throwable; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: