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

Acl Bundle Laravel Package

alchemy/acl-bundle

Symfony bundle providing a simple ACL API. Configure object types, alias your UserRepository, and add Redis cache for access tokens. Exposes endpoints to list, upsert, and delete ACEs by user/group, object type/id, with permission masks and wildcards.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Symfony Compatibility: While this is a Symfony bundle, its core ACL logic (userType, objectType, mask-based permissions) is language-agnostic and can be adapted to Laravel’s Eloquent/Policy system. The metadata feature (1.1.0) aligns with Laravel’s attribute system (#[Attribute]), enabling declarative ACLs.
    • Granularity: Supports object-level permissions (e.g., Publication#42), which Laravel’s built-in Gate/Policy lacks natively. Useful for SaaS platforms with dynamic access rules.
    • API-Driven: The REST endpoints (/permissions/aces, /permissions/ace) can be consumed by Laravel’s HTTP client (Illuminate\Support\Facades\Http) for admin panels or background jobs.
    • Redis Caching: The optional Redis pool for access tokens integrates with Laravel’s Redis facade, reducing latency for permission checks.
    • Metadata Extensibility: Enables audit trails, time-bound permissions, or contextual rules (e.g., metadata: {expires_at: "2024-12-31"}), which can be mapped to Laravel’s attributes or accessors.
  • Cons:

    • Symfony Dependency Overhead: Requires Symfony components (e.g., symfony/options-resolver, symfony/attribute), which may conflict with Laravel’s ecosystem. Mitigate with composer.json overrides or a custom wrapper.
    • Mask-Based Permissions: Laravel’s Gate/Policy uses named methods (can('edit')), while this bundle uses numeric masks (mask: 7). Requires a translation layer (e.g., maskToPermission() helper).
    • No Native Laravel Integration: No Eloquent models, service providers, or Artisan commands. Must be adapted manually (e.g., Doctrine → Eloquent, Symfony events → Laravel events).
    • Metadata Complexity: Symfony’s metadata system may not align perfectly with Laravel’s #[Attribute] or accessors. Requires custom serialization/deserialization.

Integration Feasibility

  • Core Components:

    • ACL Core:
      • Replace Symfony’s UserRepositoryInterface with Laravel’s App\Models\User via a facade or service container alias.
      • Map alchemy_acl.objects (YAML) to Laravel’s config (config/acl.php):
        'objects' => [
            'publication' => App\Models\Publication::class,
            'asset' => App\Models\Asset::class,
        ],
        
    • Metadata System:
      • Use Laravel’s #[Attribute] for declarative ACLs:
        use Alchemy\AclBundle\Attribute\AclObject;
        #[AclObject(objectType: 'publication')]
        class Publication extends Model { ... }
        
      • For non-attribute users, fallback to config-based registration (e.g., Acl::registerObject('publication', Publication::class)).
    • Redis Cache:
      • Leverage Laravel’s Redis facade to configure the accessToken.cache pool:
        Cache::extend('accessToken', function () {
            return Cache::repository(new RedisStore(config('cache.redis')));
        });
        
    • API Endpoints:
      • Consume the bundle’s endpoints via Laravel’s Http client:
        $aces = Http::get('http://symfony-app/permissions/aces', [
            'objectType' => 'publication',
            'objectId' => 'pub-42',
        ]);
        
      • For internal use, create a Laravel service that proxies these calls (e.g., AclService::getAces()).
  • Challenges:

    • Symfony Component Conflicts: Resolve with:
      "extra": {
        "laravel": {
          "dont-discover": ["symfony/*"]
        }
      }
      
    • Doctrine → Eloquent: Replace Doctrine queries with Laravel’s Query Builder or Eloquent ORM.
    • Event System: Symfony’s event dispatcher must be mocked or replaced with Laravel’s Events system.
    • Mask Permissions: Create a helper class to map masks to Laravel’s Gate logic:
      class AclMask {
          public static function maskToPermission(int $mask): string {
              return match ($mask) {
                  1 => 'view',
                  2 => 'edit',
                  4 => 'delete',
                  7 => 'full-access',
                  default => 'unknown',
              };
          }
      }
      

Technical Risk

  • High:
    • Symfony Dependency Risks: Conflicts with Laravel’s symfony/* packages (e.g., symfony/http-foundation vs. Laravel’s Illuminate/Http). Requires isolation testing in a separate repo.
    • Metadata Integration: Symfony’s metadata system may not work seamlessly with Laravel’s #[Attribute]. Test with:
      $reflection = new ReflectionClass(Publication::class);
      $attributes = $reflection->getAttributes(AclObject::class);
      
    • Performance Overhead: Redis caching helps, but metadata reflection could slow down boot time. Benchmark with:
      php artisan optimize:clear && php -d opcache.enable=0 artisan tinker
      
    • Breaking Changes: Symfony 7’s Attribute system may not fully support Laravel’s #[Attribute] syntax. Fallback to YAML config if needed.
  • Mitigation:
    • Wrapper Layer: Create a Laravel-specific facade (e.g., AclFacade) to abstract Symfony dependencies.
    • Fallback Config: Use alchemy_acl.objects in YAML if metadata fails.
    • Incremental Testing: Start with non-critical entities (e.g., LogEntry) before applying to Publication/Asset.

Key Questions

  1. Symfony Dependency Strategy:

    • Should we isolate the bundle in a separate Symfony micro-service (via API) or force-integrate it into Laravel?
    • Are there Laravel-compatible alternatives (e.g., spatie/laravel-permission + custom object-level logic)?
  2. Metadata Implementation:

    • Will we use Laravel’s #[Attribute] or Symfony’s metadata system? If the latter, how will we handle reflection differences?
    • How will metadata be stored/retrieved? As JSON in a DB column or via a separate table?
  3. Permission Mask Design:

    • Should we map masks to Laravel’s Gate (e.g., mask: 7can('full-access')) or create a hybrid system?
    • How will custom permissions (e.g., publish) be defined? Via masks or additional metadata?
  4. Performance Tradeoffs:

    • Is Redis caching sufficient for high-traffic permission checks, or should we add a local cache layer (e.g., Illuminate\Support\Facades\Cache)?
    • How will metadata-heavy queries (e.g., filtering by metadata.expires_at) impact DB performance?
  5. Admin Tooling:

    • Will we build a Laravel admin panel to manage ACLs (via the bundle’s API) or use a third-party tool (e.g., spatie/laravel-permission UI)?
    • How will audit logs (from metadata) be surfaced to admins?
  6. Migration Path:

    • How will existing Laravel Gate/Policy logic coexist with this bundle? Should we deprecate Gates in favor of the bundle’s API?
    • What’s the rollback plan if integration fails? Can we revert to spatie/laravel-permission?

Integration Approach

Stack Fit

  • Laravel Compatibility:

    • Pros:
      • Redis Integration: Laravel’s Redis facade works seamlessly with the bundle’s accessToken.cache.
      • HTTP Client: The bundle’s REST API can be consumed via Illuminate\Support\Facades\Http.
      • Attribute System: Laravel’s #[Attribute] can replace Symfony’s metadata system with minimal effort.
    • Cons:
      • Symfony Dependencies: Requires composer overrides or a micro-service approach to avoid conflicts.
      • Doctrine ORM: Must be replaced with Eloquent or a data mapper (e.g., laravel-doctrine/orm).
      • Event System: Symfony’s events must be mapped to Laravel’s Events system.
  • Hybrid Architecture:

    • Option 1: Direct Integration (High Risk):
      • Replace Symfony components with Laravel equivalents (e.g., symfony/attributeilluminate/support/Traits).
      • Use facades to abstract Symfony-specific logic (e.g., Acl::getAces() → `
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.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony