1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Routing\Loader; |
4
|
|
|
|
5
|
|
|
use LAG\AdminBundle\Admin\Resource\AdminResource; |
6
|
|
|
use LAG\AdminBundle\Exception\ConfigurationException; |
7
|
|
|
use LAG\AdminBundle\Exception\Exception; |
8
|
|
|
use LAG\AdminBundle\Factory\Configuration\ActionConfigurationFactoryInterface; |
9
|
|
|
use LAG\AdminBundle\Factory\Configuration\AdminConfigurationFactoryInterface; |
10
|
|
|
use Symfony\Component\Routing\Route; |
11
|
|
|
use Symfony\Component\Routing\RouteCollection; |
12
|
|
|
|
13
|
|
|
class ResourceLoader implements ResourceLoaderInterface |
14
|
|
|
{ |
15
|
|
|
public function __construct( |
16
|
|
|
private AdminConfigurationFactoryInterface $adminConfigurationFactory, |
17
|
|
|
private ActionConfigurationFactoryInterface $actionConfigurationFactory, |
18
|
|
|
) { |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function loadRoutes(AdminResource $resource, RouteCollection $routes): void |
22
|
|
|
{ |
23
|
|
|
$configuration = $this |
24
|
|
|
->adminConfigurationFactory |
25
|
|
|
->create($resource->getName(), $resource->getConfiguration()) |
26
|
|
|
; |
27
|
|
|
|
28
|
|
|
foreach ($configuration->get('actions') as $name => $options) { |
29
|
|
|
try { |
30
|
|
|
$actionConfiguration = $this->actionConfigurationFactory->create( |
31
|
|
|
$resource->getName(), |
32
|
|
|
$name, |
33
|
|
|
$options |
34
|
|
|
); |
35
|
|
|
} catch (Exception $exception) { |
36
|
|
|
throw new ConfigurationException('admin', $resource->getName(), $exception); |
37
|
|
|
} |
38
|
|
|
$route = new Route($actionConfiguration->getPath(), [ |
39
|
|
|
'_controller' => $actionConfiguration->getController(), |
40
|
|
|
'_admin' => $actionConfiguration->getAdminName(), |
41
|
|
|
'_action' => $actionConfiguration->getName(), |
42
|
|
|
], array_keys($actionConfiguration->getRouteParameters())); |
43
|
|
|
|
44
|
|
|
$routes->add($actionConfiguration->get('route'), $route); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|