New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PoC new Module system to SSP 2.0 #1294
base: master
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,11 @@ | |||
<?php | |||
|
|||
return [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
||
$routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Load routes required by simplesaml to work. For example the route required to have the debug toolbar.
lib/SimpleSAML/Kernel.php
Outdated
* @return void | ||
*/ | ||
private function registerModuleControllers(ContainerBuilder $container): void | ||
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -162,12 +162,12 @@ public function asset(string $asset, string $module = null): string | |||
{ | |||
$baseDir = $this->configuration->getBaseDir(); | |||
if (is_null($module)) { | |||
$file = $baseDir . 'www/assets/' . $asset; | |||
$file = $baseDir . 'www/' . $asset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
29f7b69
to
1a911ce
Compare
c7c8357
to
fdbe001
Compare
3b5f5ba
to
96357ee
Compare
7587851
to
d523b31
Compare
8c90121
to
d534e3b
Compare
bc1c5c8
to
d0a5974
Compare
ccb9b02
to
120a100
Compare
6004a77
to
58bf8db
Compare
This PR is related to #1286 issue.
Changes:
www/new.php
is created to load new kernel. Alsoconsole
has been changed to load the new kernel.ModuleKernel.php
to indicate than only works with one module.Instructions:
APP_ENV=dev
environment variable must be configuredcomposer install
. This will install [a demo module](https://packagist.org/packages/sgomez/simplesamlphp-module-expirycheck.modules.php
insideconfig-templates
toconfig
directory.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.