1 | <?php |
||
41 | class ControllerProvider implements ControllerProviderInterface |
||
42 | { |
||
43 | |||
44 | /** |
||
45 | * Setups the templates. |
||
46 | * |
||
47 | * @param Application $app |
||
48 | * the Application instance of the Silex application |
||
49 | */ |
||
50 | 1 | protected function setupTemplates(Application $app) |
|
56 | |||
57 | /** |
||
58 | * Setups the routes. |
||
59 | * |
||
60 | * @param Application $app |
||
61 | * the Application instance of the Silex application |
||
62 | * |
||
63 | * @return mixed |
||
64 | * the created controller factory |
||
65 | */ |
||
66 | 1 | protected function setupRoutes(Application $app) |
|
67 | { |
||
68 | 1 | $controller = $app->offsetExists('crud.controller') ? $app['crud.controller'] : new Controller($app['crud'], $app['crud.filesystem'], $app['twig'], $app['session'], $app['translator']); |
|
69 | 1 | if (!$controller instanceof ControllerInterface) { |
|
70 | 1 | throw new \InvalidArgumentException('crud.controller doesn\'t implement CRUDlex\ControllerInterface.'); |
|
71 | } |
||
72 | 1 | $localeAndCheckEntity = [$controller, 'setLocaleAndCheckEntity']; |
|
73 | 1 | $factory = $app['controllers_factory']; |
|
74 | 1 | $factory->get('/resource/static', [$controller, 'staticFile'])->bind('crudStatic'); |
|
75 | 1 | $factory->match('/{entity}/create', [$controller, 'create'])->bind('crudCreate')->before($localeAndCheckEntity, 10); |
|
76 | 1 | $factory->get('/{entity}', [$controller, 'showList'])->bind('crudList')->before($localeAndCheckEntity, 10); |
|
77 | 1 | $factory->get('/{entity}/{id}', [$controller, 'show'])->bind('crudShow')->before($localeAndCheckEntity, 10); |
|
78 | 1 | $factory->match('/{entity}/{id}/edit', [$controller, 'edit'])->bind('crudEdit')->before($localeAndCheckEntity, 10); |
|
79 | 1 | $factory->post('/{entity}/{id}/delete', [$controller, 'delete'])->bind('crudDelete')->before($localeAndCheckEntity, 10); |
|
80 | 1 | $factory->get('/{entity}/{id}/{field}/file', [$controller, 'renderFile'])->bind('crudRenderFile')->before($localeAndCheckEntity, 10); |
|
81 | 1 | $factory->post('/{entity}/{id}/{field}/delete', [$controller, 'deleteFile'])->bind('crudDeleteFile')->before($localeAndCheckEntity, 10); |
|
82 | 1 | $factory->get('/setting/locale/{locale}', [$controller, 'setLocale'])->bind('crudSetLocale'); |
|
83 | |||
84 | 1 | return $factory; |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * Setups i18n. |
||
89 | * |
||
90 | * @param Application $app |
||
91 | * the Application instance of the Silex application |
||
92 | */ |
||
93 | 1 | protected function setupI18n(Application $app) |
|
94 | { |
||
95 | $app->before(function(Request $request, Application $app) { |
||
96 | $manageI18n = $app['crud']->isManageI18n(); |
||
97 | if ($manageI18n) { |
||
98 | $locale = $app['session']->get('locale', 'en'); |
||
99 | $app['translator']->setLocale($locale); |
||
100 | } |
||
101 | 1 | }, 1); |
|
102 | 1 | } |
|
103 | |||
104 | /** |
||
105 | * Implements ControllerProviderInterface::connect() connecting this |
||
106 | * controller. |
||
107 | * |
||
108 | * @param Application $app |
||
109 | * the Application instance of the Silex application |
||
110 | * |
||
111 | * @return \Silex\ControllerCollection |
||
112 | * this method is expected to return the used ControllerCollection instance |
||
113 | */ |
||
114 | 1 | public function connect(Application $app) |
|
121 | |||
122 | } |
||
123 |