Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Relay Core Connector Textfile Bundle Laravel Package

dbp/relay-core-connector-textfile-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. 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],
    
  2. 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
    
  3. 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:

    • Quick API access control testing.
    • Mocking user attributes for Relay API endpoints during development.

Implementation Patterns

Workflows

  1. Role-Based Access Control (RBAC) Setup

    • Define groups in dbp_relay_core_connector_textfile.yaml and map them to user emails.
    • Example:
      groups:
          super_admin:
              - admin@example.com
          restricted:
              - user@example.com
      
    • Use these groups in your API logic (e.g., via AuthorizationDataProviderInterface).
  2. Integration with Relay API

    • The bundle implements AuthorizationDataProviderInterface, so it integrates seamlessly with Relay’s built-in authorization system.
    • No additional middleware or service registration is needed if the bundle is correctly ordered in bundles.php.
  3. Dynamic Attribute Assignment

    • Extend the config to include custom attributes (e.g., permissions, metadata) for fine-grained control:
      groups:
          developers:
              - dev1@example.com
              attributes:
                  max_api_calls: 1000
                  allowed_routes: ['/api/v1/*']
      

Tips for Daily Use

  • Use for Local/Dev Environments: Avoid database dependencies during development by leveraging the textfile config.
  • Combine with Other Providers: Use this bundle alongside database-backed providers (e.g., DbpRelayCoreConnectorDoctrineBundle) for hybrid setups.
  • Leverage Symfony’s Parameter Bag: Access the loaded groups via dependency injection:
    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');
    }
    

Gotchas and Tips

Pitfalls

  1. Bundle Order Matters

    • If placed after DbpRelayCoreBundle in bundles.php, the AuthorizationDataProviderInterface may not be registered correctly.
    • Fix: Ensure the textfile bundle is listed first in the array.
  2. YAML Syntax Errors

    • Invalid YAML (e.g., unquoted emails with special characters) will cause silent failures.
    • Fix: Validate your config with a YAML linter or use tools like YAMLLint.
  3. No Real-Time Updates

    • Changes to the config file require a cache clear (php bin/console cache:clear) to take effect.
    • Workaround: Use a file watcher (e.g., Laravel Mix’s notify) or a custom event listener to reload the config dynamically.
  4. Limited Scalability

    • Not suitable for production with hundreds of users/roles (use a database-backed provider instead).
    • Tip: Use this bundle only for development or small-scale testing.

Debugging

  • 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.

Extension Points

  1. Custom Attribute Providers

    • Extend the bundle’s 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)
              );
          }
      }
      
  2. Override Default Behavior

    • Replace the bundle’s service definition in config/services.yaml:
      services:
          Dbp\Relay\CoreConnectorTextfileBundle\Authorization\TextfileAuthorizationDataProvider:
              arguments:
                  $groups: '%env(DBP_RELAY_GROUPS)%'  # Use env vars for flexibility
      
  3. Event Listeners for Dynamic Reloads

    • Listen to kernel events to reload the config without manual cache clears:
      // src/EventListener/ConfigReloadListener.php
      class ConfigReloadListener
      {
          public function onKernelRequest(GetResponseEvent $event)
          {
              if ($event->isMasterRequest() && $this->shouldReloadConfig()) {
                  $this->reloadConfig();
              }
          }
      }
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware