|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2024 SURFnet bv |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Surfnet\StepupGateway\GatewayBundle\Container; |
|
20
|
|
|
|
|
21
|
|
|
use Exception; |
|
22
|
|
|
use Psr\Container\ContainerInterface; |
|
23
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* ! This should be a temporary construction ! |
|
27
|
|
|
* |
|
28
|
|
|
* The container controller is a means to allow access to the service container |
|
29
|
|
|
* in the controllers. Allowing the controller actions to ->get services from |
|
30
|
|
|
* within the controller actions. |
|
31
|
|
|
* |
|
32
|
|
|
* This is highly discouraged, but we needed it to get a working Gateway with |
|
33
|
|
|
* SF6 support. See: https://www.pivotaltracker.com/story/show/187475121 |
|
34
|
|
|
*/ |
|
35
|
|
|
class ContainerController extends AbstractController |
|
36
|
|
|
{ |
|
37
|
|
|
/** @var ContainerInterface */ |
|
38
|
|
|
protected $serviceContainer; |
|
39
|
|
|
|
|
40
|
|
|
public function setServiceContainer(ContainerInterface $container): void |
|
41
|
|
|
{ |
|
42
|
|
|
$this->serviceContainer = $container; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function get(string $serviceName): mixed |
|
46
|
|
|
{ |
|
47
|
|
|
$logger = $this->serviceContainer->get('logger'); |
|
48
|
|
|
$logger->info( |
|
49
|
|
|
sprintf( |
|
50
|
|
|
'Reading the "%s" service from the container (temporary ContainerController solution)', |
|
51
|
|
|
$serviceName |
|
52
|
|
|
) |
|
53
|
|
|
); |
|
54
|
|
|
try { |
|
55
|
|
|
$service = $this->container->get($serviceName); |
|
56
|
|
|
} catch (Exception) { |
|
57
|
|
|
$service = $this->serviceContainer->get($serviceName); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $service; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|