PoC new Module system to SSP 2.0#1294
Conversation
| @@ -0,0 +1,11 @@ | |||
| <?php | |||
|
|
|||
| return [ | |||
There was a problem hiding this comment.
This file returns all modules/bundles to be loaded. The kernel supports environments, so we can indicate if they should be loaded in all or just in a few of them.
|
|
||
| return [ | ||
| // Don't remove this bundles | ||
| Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], |
There was a problem hiding this comment.
Probably FrameworkBundle is too huge to be used and we can create a custom one.
| /** | ||
| * @param string $module | ||
| */ | ||
| public function __construct(string $module) |
There was a problem hiding this comment.
New Kernel is not just for one module.
| $confDir = Module::getModuleDir($this->module) . '/routing/services'; | ||
| if (is_dir($confDir)) { | ||
| $loader->load($confDir . '/**/*' . self::CONFIG_EXTS, 'glob'); | ||
| foreach ($this->bundles as $bundle) { |
There was a problem hiding this comment.
This iterator search in all bundles the ones that are SSP Modules and checks if they have a routes directory (and load the route files). The module name is used a prefix to the url.
| } | ||
| $confDir = __DIR__ . '/Resources/config'; | ||
|
|
||
| $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob'); |
There was a problem hiding this comment.
Load routes required by simplesaml to work. For example the route required to have the debug toolbar.
| * @return void | ||
| */ | ||
| private function registerModuleControllers(ContainerBuilder $container): void | ||
| protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) |
There was a problem hiding this comment.
Load services required by the core of simplesaml (modules services are loaded inside the Module loader class).
| use Symfony\Component\DependencyInjection\Loader\DirectoryLoader; | ||
| use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
|
||
| abstract class Module extends Bundle |
There was a problem hiding this comment.
This abstract class extends from Symfony Bundle abstract class. So a module is a bundle. Probably we can create a thin abstract class because we don't require all the logic inside the base class.
| { | ||
| abstract public function getShortName(): string; | ||
|
|
||
| public function build(ContainerBuilder $container) |
There was a problem hiding this comment.
This method is called when the cache is warmed. Here we can define the services this module will use.
| * @param ContainerBuilder $container | ||
| * @return void | ||
| */ | ||
| private function registerModuleControllers(ContainerBuilder $container): void |
There was a problem hiding this comment.
We register controller services. The idea is to create similar methods for each service we want to define automatically (hooks/events, admin menus, etc.). The possibility to use a services.yml to load custom services will be available. But this methods exists to do the module development easiest.
| $baseDir = $this->configuration->getBaseDir(); | ||
| if (is_null($module)) { | ||
| $file = $baseDir . 'www/assets/' . $asset; | ||
| $file = $baseDir . 'www/' . $asset; |
There was a problem hiding this comment.
I use symfony/asset module that implements asset function in twig. This modification is to have the same behaviour in the old a new way to read templates.
|
Translations in symfony supports a lot of loaders (po, yaml, xliff, csv, ...). Gettext loader (po files) does not require gettext php module (apparently, I will investigate more about this). There are a difference. The structure of translations files change from |
|
Oops, I did not intend to do this, but @sgomez should this be merged at some point? Let's not let this go to waste.. |
|
Hi @tvdijen This is just a PoC. This requires a lot of discussion because is a huge change in the way modules are loaded. |
1c686ab to
eb20457
Compare
08ebb9c to
64fca25
Compare
Required to run the tests for simplesamlphp/simplesamlphp#1294
tvdijen
left a comment
There was a problem hiding this comment.
The RouteCollectionBuilder was deprecated by Symfony in favour of the RoutingConfigurator.
Unfortunately I can't get it to work with the new class and I don't know what to do with the $prefix variable.
7a53fc8 to
d73ae47
Compare
7b173cf to
3326beb
Compare
8ac729b to
a16cf6e
Compare
fc454de to
7ac76ae
Compare
29f7b69 to
1a911ce
Compare
c7c8357 to
fdbe001
Compare
b639fc0 to
a6df6e9
Compare
This PR is related to #1286 issue.
Changes:
www/new.phpis created to load new kernel. Alsoconsolehas been changed to load the new kernel.ModuleKernel.phpto indicate than only works with one module.Instructions:
APP_ENV=devenvironment variable must be configuredcomposer install. This will install [a demo module](https://packagist.org/packages/sgomez/simplesamlphp-module-expirycheck.modules.phpinsideconfig-templatestoconfigdirectory.I have this authsource to check the module:
And this filter:
The idea is to run the ExpiredController and load templates and translation from vendor without install the modules inside simplesamlphp directory.
More explanations in the code.