and let’s assume the following content of Bar.php:
// Bar.phpnamespaceOtherDir;useSomeDir\Foo;// This now conflicts the class OtherDir\Foo
If both files OtherDir/Foo.php and SomeDir/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 before OtherDir/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:
// Bar.phpnamespaceOtherDir;useSomeDir\FooasSomeDirFoo;// There is no conflict anymore.
Loading history...
18
use Jose\Component\KeyManagement\X5UFactory;
19
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\Definition;
22
use Symfony\Component\DependencyInjection\Reference;
23
24
class X5U extends AbstractSource implements JWKSetSource
25
{
26
/**
27
* {@inheritdoc}
28
*/
29
public function createDefinition(ContainerBuilder $container, array $config): Definition
30
{
31
$definition = new Definition(JWKSet::class);
32
$definition->setFactory([
33
new Reference(X5UFactory::class),
34
'loadFromUrl',
35
]);
36
$definition->setArguments([
37
$config['url'],
38
$config['headers'],
39
]);
40
$definition->addTag('jose.jwkset');
41
42
return $definition;
43
}
44
45
/**
46
* {@inheritdoc}
47
*/
48
public function getKeySet(): string
49
{
50
return 'x5u';
51
}
52
53
/**
54
* {@inheritdoc}
55
*/
56
public function addConfiguration(NodeDefinition $node)
57
{
58
parent::addConfiguration($node);
59
$node
60
->children()
61
->scalarNode('url')
62
->info('URL of the key set.')
63
->isRequired()
64
->end()
65
->arrayNode('headers')
66
->treatNullLike([])
67
->treatFalseLike([])
68
->info('Header key/value pairs added to the request.')
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: