diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index cf23e241a2..495c67806c 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -114,6 +114,7 @@ use Neutron\Silex\Provider\FilesystemServiceProvider; use Neutron\ReCaptcha\ReCaptchaServiceProvider; use PHPExiftool\PHPExiftoolServiceProvider; use Silex\Application as SilexApplication; +use Silex\ControllerProviderInterface; use Silex\Provider\FormServiceProvider; use Silex\Provider\MonologServiceProvider; use Silex\Provider\SessionServiceProvider; @@ -833,6 +834,8 @@ class Application extends SilexApplication $this->mount('/thesaurus', new Thesaurus()); $this->mount('/xmlhttp', new ThesaurusXMLHttp()); + + $this->bindPluginRoutes('plugin.controller_providers.root'); } /** @@ -854,4 +857,36 @@ class Application extends SilexApplication { return static::$flashTypes; } + + /** + * @param $routeParameter + */ + public function bindPluginRoutes($routeParameter) + { + foreach ($this[$routeParameter] as $provider) { + $prefix = ''; + + if (is_array($provider)) { + $providerDefinition = $provider; + list($prefix, $provider) = $providerDefinition; + } + + if (!is_string($prefix) || !is_string($provider)) { + continue; + } + + $prefix = '/' . ltrim($prefix, '/'); + if (!isset($this[$provider])) { + continue; + } + + $provider = $this[$provider]; + + if (!$provider instanceof ControllerProviderInterface) { + continue; + } + + $this->mount($prefix, $provider); + } + } } diff --git a/lib/Alchemy/Phrasea/Application/Api.php b/lib/Alchemy/Phrasea/Application/Api.php index 4387f948a6..38612ca7e7 100644 --- a/lib/Alchemy/Phrasea/Application/Api.php +++ b/lib/Alchemy/Phrasea/Application/Api.php @@ -129,6 +129,7 @@ return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) { $app->mount('/api/oauthv2', new Oauth2()); $app->mount('/datafiles/', new Datafiles()); $app->mount('/api/v1', new V1()); + $app->bindPluginRoutes('plugin.controller_providers.api'); $app['dispatcher']->addSubscriber(new ApiOauth2ErrorsSubscriber($app['phraseanet.exception_handler'])); $app['dispatcher']->addSubscriber(new ApiCorsSubscriber($app)); diff --git a/lib/Alchemy/Phrasea/Core/Provider/PluginServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/PluginServiceProvider.php index 9423c975d3..2af17fb58a 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/PluginServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/PluginServiceProvider.php @@ -23,6 +23,16 @@ class PluginServiceProvider implements ServiceProviderInterface }); $app['plugin.locale.textdomains'] = new \ArrayObject(); + + // Routes will be bound after all others + // Add a new controller provider can be added as follows + // $app['plugin.controller_providers'][] = array('/prefix', 'controller_provider_service_key'); + $app['plugin.controller_providers.root'] = new \ArrayObject(); + + // Routes will be bound after all others + // Add a new controller provider can be added as follows + // $app['plugin.controller_providers'][] = array('/prefix', 'controller_provider_service_key'); + $app['plugin.controller_providers.api'] = new \ArrayObject(); } public function boot(Application $app)