dbp/relay-core-connector-textfile-bundle
Installation
composer require dbp/relay-core-connector-textfile-bundle
Ensure your config/bundles.php includes the bundle before DbpRelayCoreBundle:
Dbp\Relay\CoreConnectorTextfileBundle\DbpRelayCoreConnectorTextfileBundle::class => ['all' => true],
Dbp\Relay\CoreBundle\DbpRelayCoreBundle::class => ['all' => true],
Configure the Bundle
Create config/packages/dbp_relay_core_connector_textfile.yaml with a basic groups structure:
dbp_relay_core_connector_textfile:
groups:
admin:
- user1@example.com
- user2@example.com
editor:
- user3@example.com
First Use Case Use this bundle to simplify local development or prototyping by defining user roles/groups in a YAML file instead of a database. Ideal for:
Role-Based Access Control (RBAC) Setup
dbp_relay_core_connector_textfile.yaml and map them to user emails.groups:
super_admin:
- admin@example.com
restricted:
- user@example.com
AuthorizationDataProviderInterface).Integration with Relay API
AuthorizationDataProviderInterface, so it integrates seamlessly with Relay’s built-in authorization system.bundles.php.Dynamic Attribute Assignment
groups:
developers:
- dev1@example.com
attributes:
max_api_calls: 1000
allowed_routes: ['/api/v1/*']
DbpRelayCoreConnectorDoctrineBundle) for hybrid setups.use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
public function __construct(private ParameterBagInterface $params) {}
public function getGroups(): array
{
return $this->params->get('dbp_relay_core_connector_textfile.groups');
}
Bundle Order Matters
DbpRelayCoreBundle in bundles.php, the AuthorizationDataProviderInterface may not be registered correctly.YAML Syntax Errors
No Real-Time Updates
php bin/console cache:clear) to take effect.notify) or a custom event listener to reload the config dynamically.Limited Scalability
Check Loaded Config: Dump the loaded groups in a controller or command to verify the config is parsed correctly:
$groups = $this->params->get('dbp_relay_core_connector_textfile.groups');
dump($groups);
Enable Debug Mode:
Set APP_DEBUG=true in .env to surface any configuration or dependency injection errors.
Custom Attribute Providers
AuthorizationDataProvider to fetch attributes from other sources (e.g., environment variables, API calls):
// src/Service/CustomAttributeProvider.php
class CustomAttributeProvider implements AuthorizationDataProviderInterface
{
public function getAuthorizationData(string $userEmail): array
{
// Merge textfile data with custom logic
return array_merge(
$this->textfileProvider->getAuthorizationData($userEmail),
$this->fetchCustomAttributes($userEmail)
);
}
}
Override Default Behavior
config/services.yaml:
services:
Dbp\Relay\CoreConnectorTextfileBundle\Authorization\TextfileAuthorizationDataProvider:
arguments:
$groups: '%env(DBP_RELAY_GROUPS)%' # Use env vars for flexibility
Event Listeners for Dynamic Reloads
// src/EventListener/ConfigReloadListener.php
class ConfigReloadListener
{
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->isMasterRequest() && $this->shouldReloadConfig()) {
$this->reloadConfig();
}
}
}
How can I help you explore Laravel packages today?