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

antares/accessible-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Package
    composer require antares/accessible-bundle
    
  2. Enable the Bundle Add to config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 3):
    Antares\Bundle\AccessibleBundle\AntaresAccessibleBundle::class => ['all' => true],
    
  3. Enable Property Access Magic Add to config/packages/framework.yaml:
    framework:
        property_access:
            magic_call: true
    

First Use Case: Annotated Getters/Setters

Create a DTO or entity with annotations:

use Antares\Accessible\Annotations as Access;
use Symfony\Component\Validator\Constraints as Assert;

class User
{
    use \Antares\Accessible\AutomatedBehaviorTrait;

    /**
     * @Access({Access::GET, Access::SET})
     * @Assert\Email
     */
    private $email;

    /**
     * @Access({Access::GET, Access::SET})
     * @Assert\Length(min=3, max=20)
     */
    private $username;
}

Usage:

$user = new User();
$user->setEmail('test@example.com'); // Validates via constraints
$user->setUsername('abc'); // Throws exception (too short)

Implementation Patterns

Core Workflows

  1. DTO/POJO Management Use AutomatedBehaviorTrait to auto-generate getters/setters for private properties with annotations. Example:

    class OrderItem
    {
        use AutomatedBehaviorTrait;
    
        /**
         * @Access({Access::GET, Access::SET})
         * @Assert\Positive
         */
        private $quantity;
    }
    
  2. Validation Integration Leverage Symfony’s validator constraints (e.g., @Assert\NotBlank) alongside @Access annotations.

    /**
     * @Access({Access::GET, Access::SET})
     * @Assert\NotBlank
     * @Assert\Regex("/^[A-Z]{2}-\d{4}$/")
     */
    private $licensePlate;
    
  3. Initialization Logic Use @Initialize to set default values:

    /**
     * @Access({Access::GET, Access::SET})
     * @Initialize("now")
     */
    private $createdAt;
    
  4. Collections & Associations Define relationships with @AccessibleCollection or @AccessibleObject:

    /**
     * @AccessibleCollection
     * @Assert\All({
     *     @Assert\Type("App\Entity\Tag")
     * })
     */
    private $tags;
    

Integration Tips

  • Symfony Forms: Bind annotated properties directly to form fields.
    $builder->add('email', EmailType::class);
    
  • API Platform: Use with @ApiProperty for automatic serialization.
  • Doctrine ORM: Combine with @ORM\Column for database-backed properties.

Gotchas and Tips

Common Pitfalls

  1. Cache Invalidation

    • Enable caching (antares_accessible.cache.enable: true) for performance, but clear cache after schema changes:
      php bin/console cache:clear
      
    • Symptom: Annotations ignored after property changes.
  2. Validation Overhead

    • Disable constraints validation in config/packages/antares_accessible.yaml if performance-critical:
      constraints_validation:
          enable: false
      
    • Symptom: Slow setter calls during bulk operations.
  3. Magic Call Conflicts

    • Ensure framework.property_access.magic_call: true is set; otherwise, getters/setters won’t work.
    • Symptom: Call to undefined method errors.
  4. Annotation Parsing

    • Use php bin/console debug:container antares_accessible.annotations.reader to inspect the active reader.
    • Symptom: Annotations silently ignored (e.g., wrong reader class).

Debugging Tips

  • Check Generated Code Use var_dump(class_uses($object, false)) to verify AutomatedBehaviorTrait is loaded.
  • Validate Annotations Temporarily enable antares_accessible.cache.enable: false to rule out stale cache.
  • Symfony Profiler Inspect the antares_accessible tab for validation errors or access logs.

Extension Points

  1. Custom Validators Override the default validator in services.yaml:
    services:
        antares_accessible.constraints_validation.validator: '@custom.validator'
    
  2. Cache Drivers Replace PhpFileCache with ApcCache or RedisCache for distributed environments.
  3. Annotation Readers Swap Doctrine\Common\Annotations\AnnotationReader for custom logic (e.g., parsing YAML files).

Pro Tips

  • Hybrid Properties Combine @Access with @Assert and @ORM\Column for full-stack validation:
    /**
     * @Access({Access::GET, Access::SET})
     * @Assert\NotBlank
     * @ORM\Column(type="string", length=255)
     */
    private $name;
    
  • Bulk Operations Disable validation during imports:
    $user->setConstraintsValidation(false);
    $user->setEmail('test@example.com'); // Skips validation
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky