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

Accessible Bundle Laravel Package

delormejonathan/accessible-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require antares/accessible-bundle
    

    Register the bundle in config/bundles.php:

    return [
        // ...
        Antares\AccessibleBundle\AntaresAccessibleBundle::class => ['all' => true],
    ];
    
  2. Enable Annotations: Ensure Doctrine Annotations are enabled in config/packages/doctrine.yaml:

    doctrine:
        orm:
            annotations:
                filter: ~
    
  3. First Use Case: Create a simple entity with annotations:

    use Antares\Accessible\Annotation\Access;
    use Antares\Accessible\Annotation\AutomatedBehaviorTrait;
    use Symfony\Component\Validator\Constraints as Assert;
    
    class User
    {
        use AutomatedBehaviorTrait;
    
        /**
         * @Access({Access::GET, Access::SET})
         * @Assert\NotBlank
         */
        private $name;
    }
    

    Test access:

    $user = new User();
    $user->setName('John'); // Works
    $user->getName(); // Returns 'John'
    $user->setName(''); // Throws exception (due to @Assert\NotBlank)
    

Implementation Patterns

Common Workflows

  1. Dynamic Getters/Setters: Use @Access to control property access. Combine with Symfony Validator constraints for runtime validation:

    /**
     * @Access({Access::GET, Access::SET})
     * @Assert\Length(min=5, max=255)
     */
    private $username;
    
  2. Constructor Injection: Define constructor parameters with @Access:

    class Order
    {
        use AutomatedBehaviorTrait;
    
        /**
         * @Access({Access::CONSTRUCT})
         * @Assert\Positive
         */
        private $quantity;
    }
    

    Usage:

    $order = new Order(5); // Valid
    $order = new Order(-1); // Throws exception
    
  3. Collections and Associations: Use @Access with @Assert\Valid for nested objects/collections:

    /**
     * @Access({Access::GET, Access::SET})
     * @Assert\Valid()
     * @Assert\All({
     *     @Assert\Type(type="App\Entity\Product")
     * })
     */
    private $products;
    
  4. Custom Logic: Extend AutomatedBehaviorTrait or create custom traits for reusable logic:

    trait Timestampable
    {
        use AutomatedBehaviorTrait;
    
        /**
         * @Access({Access::GET, Access::SET})
         */
        private $createdAt;
    
        public function __construct()
        {
            $this->createdAt = new \DateTime();
        }
    }
    

Integration Tips

  • Symfony Forms: Bind annotated entities directly to form fields. The bundle auto-generates accessors for form handling.
  • APIs (API Platform, FOSRest): Use @Access to control serialization/deserialization. Combine with @Groups (from Symfony Serializer) for granular control.
  • Doctrine ORM: Works seamlessly with Doctrine entities. Ensure @ORM\Column annotations are present for database mapping.

Gotchas and Tips

Pitfalls

  1. Annotation Processing Order:

    • Annotations are processed at runtime, not compile-time. Ensure all required annotations (e.g., @Assert) are loaded via Symfony’s annotation autoloader.
    • Fix: Verify config/packages/framework.yaml includes:
      framework:
          validation:
              enabled: true
      
  2. Circular Dependencies:

    • Nested objects with @Assert\Valid can cause infinite loops if not handled carefully.
    • Fix: Use @MaxDepth or lazy-loading for complex hierarchies:
      @Assert\Valid(maxDepth=1)
      
  3. Private Properties:

    • The bundle relies on PHP’s magic methods. Avoid overriding __get/__set manually.
    • Fix: Use @Access annotations instead of direct property access.
  4. Performance:

    • Runtime annotation processing adds overhead. Avoid overusing annotations on performance-critical paths.
    • Fix: Cache compiled annotations (Symfony’s AnnotationReader supports caching).
  5. Symfony 5+ Deprecations:

    • The bundle is outdated (last release 2020). Some Symfony 6+ features (e.g., PHP 8 attributes) may not work.
    • Fix: Fork the package or use a modern alternative like Symfony Uid + custom traits.

Debugging Tips

  • Enable Annotation Debugging: Add this to config/packages/dev/doctrine.yaml to log processed annotations:

    doctrine:
        orm:
            annotations:
                filter: ~
                cache: false
    

    Check logs for Accessible events.

  • Validate Annotations: Use Symfony’s validator to catch issues early:

    php bin/console debug:validator App\Entity\User
    
  • Override Behavior: Extend Antares\Accessible\Accessible to customize logic:

    class CustomAccessible extends Accessible
    {
        protected function getDefaultAccess(): array
        {
            return [Access::GET, Access::SET, Access::CONSTRUCT];
        }
    }
    

    Bind it via dependency injection.

Extension Points

  1. Custom Access Levels: Extend the Access enum or create a decorator for AutomatedBehaviorTrait:

    trait CustomAccessTrait
    {
        public function __construct()
        {
            $this->addAccessRule('customRule', function () { /* ... */ });
        }
    }
    
  2. Event Listeners: Listen to accessible.post_process events to modify behavior dynamically:

    // config/services.yaml
    services:
        App\EventListener\AccessibleListener:
            tags:
                - { name: kernel.event_listener, event: accessible.post_process, method: onPostProcess }
    
  3. Integration with Laravel (via Symfony Bridge):

    • Use symfony/dependency-injection and symfony/http-kernel to integrate in Laravel.
    • Example: Create a Laravel service provider to register the bundle:
      use Antares\AccessibleBundle\AntaresAccessibleBundle;
      use Symfony\Component\HttpKernel\Kernel;
      
      class AccessibleServiceProvider extends ServiceProvider
      {
          public function register()
          {
              $kernel = new Kernel('dev', true);
              $kernel->boot();
              $this->app->singleton('accessible', function () use ($kernel) {
                  return $kernel->getContainer()->get('accessible');
              });
          }
      }
      
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours