riddlestone / brokkr-portals
A Laminas module to pull configuration together for portals, such as a public portal, an admin portal, etc.
Requires
- php: ^7.2|^8.0
- container-interop/container-interop: ^1.2
- laminas/laminas-component-installer: ^1.0 || ^2.1
- laminas/laminas-config: ^3.3
- laminas/laminas-modulemanager: ^2.8
- laminas/laminas-servicemanager: ^3.4
Requires (Dev)
- phpunit/phpunit: ^8.4
README
A Laminas module to pull configuration together for portals, such as a public portal, an admin portal, etc.
Adding Configuration
To add information about a portal, add it to a module configuration file under portals.{portal_name}
:
return [ 'portals' => [ 'main' => [ 'layout' => 'main.layout', 'css' => [ __DIR__ . '/../css/styles.css', ], 'js' => [ __DIR__ . '/../js/scripts.js', ], ], ], ];
Portals also supports lazy configuration loading through PortalConfigProviders:
return [ 'portal_manager' => [ 'provider_names' => [ 'My\\Portal\\Config\\Provider', ], 'factories' => [ 'My\\Portal\\Config\\Provider' => 'My\\Portal\\Config\\ProviderFactory', ], ], ];
Portal Features
Features allow you to group portal configuration together, and assign it to a portal separately. This might be usefuuul if some modular functionality requires multiple css/js files, but the module doesn't know which portals it will be used in:
return [ 'portals' => [ 'main' => [ 'features' => [ 'some-functionality', ], ], ], 'portal_features' => [ 'some-functionality' => [ 'css' => [ __DIR__ . '/../css/styles.css', ], 'js' => [ __DIR__ . '/../js/scripts.js', ], ], ], ];
Here the module can define the js and css required for portal_features/some-functionality, and the project can declare that portals/main uses it.
Getting the Portal Manager
/** @var \Laminas\ServiceManager\ServiceManager $serviceManager */ $portalManager = $serviceManager->get(\Riddlestone\Brokkr\Portals\PortalManager::class);
Getting Configuration
/** @var \Riddlestone\Brokkr\Portals\PortalManager $portalManager */ # get a list of portals $portals = $portalManager->getPortalNames(); # set the current portal $portalManager->setCurrentPortalName('main'); # get the current portal name $portalName = $portalManager->getCurrentPortalName(); # check a portal has config $hasConfig = $portalManager->hasPortalConfig('main', 'css'); # check the current portal has config $hasConfig = $portalManager->hasCurrentPortalConfig('css'); # get the config for a portal $portalConfig = $portalManager->getPortalConfig('main', 'css'); # get the config for the current portal $portalConfig = $portalManager->getCurrentPortalConfig('css');