composer require antares/accessible-bundle
config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 3):
Antares\Bundle\AccessibleBundle\AntaresAccessibleBundle::class => ['all' => true],
config/packages/framework.yaml:
framework:
property_access:
magic_call: true
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)
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;
}
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;
Initialization Logic
Use @Initialize to set default values:
/**
* @Access({Access::GET, Access::SET})
* @Initialize("now")
*/
private $createdAt;
Collections & Associations
Define relationships with @AccessibleCollection or @AccessibleObject:
/**
* @AccessibleCollection
* @Assert\All({
* @Assert\Type("App\Entity\Tag")
* })
*/
private $tags;
$builder->add('email', EmailType::class);
@ApiProperty for automatic serialization.@ORM\Column for database-backed properties.Cache Invalidation
antares_accessible.cache.enable: true) for performance, but clear cache after schema changes:
php bin/console cache:clear
Validation Overhead
config/packages/antares_accessible.yaml if performance-critical:
constraints_validation:
enable: false
Magic Call Conflicts
framework.property_access.magic_call: true is set; otherwise, getters/setters won’t work.Call to undefined method errors.Annotation Parsing
php bin/console debug:container antares_accessible.annotations.reader to inspect the active reader.var_dump(class_uses($object, false)) to verify AutomatedBehaviorTrait is loaded.antares_accessible.cache.enable: false to rule out stale cache.antares_accessible tab for validation errors or access logs.services.yaml:
services:
antares_accessible.constraints_validation.validator: '@custom.validator'
PhpFileCache with ApcCache or RedisCache for distributed environments.Doctrine\Common\Annotations\AnnotationReader for custom logic (e.g., parsing YAML files).@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;
$user->setConstraintsValidation(false);
$user->setEmail('test@example.com'); // Skips validation
How can I help you explore Laravel packages today?