symfony/property-access
Symfony PropertyAccess lets you read and write values on objects and arrays using a simple property path string notation. It supports nested access, getters/setters, and array indexes, making data mapping and form handling easier.
user.address.city), reducing fragmentation in traversal logic (e.g., mix of getX(), Arr::get(), and direct properties).spatie/laravel-data or laravel/serializable-closure for DTOs/serialization."user.tier.discount"), reducing hardcoded conditional logic.symfony/property-access) with minimal setup. Works alongside Laravel’s native helpers without conflicts.PropertyAccess in a Laravel facade (e.g., Property::get($object, 'path')) to hide Symfony-specific syntax.Validator, Form, and Serializer components, reducing duplication (e.g., for form field mapping or validation rules).'user.profile.settings' paths).PropertyAccess supports this).'user.password'). Mitigation: Implement a whitelist/blacklist for allowed paths or use Laravel’s Str::of() for sanitization.^6.4 for older PHP versions but lose modern syntax support.Arr::get() or manual traversal may need training. Mitigation: Provide a migration guide and examples (e.g., replacing $user->getAddress()->getCity() with Property::get($user, 'address.city')).user.*).Property::set($obj, 'path', $value)).PropertyAccessException or wrap it in Laravel’s Handler for user-friendly messages.Arr::get() for arrays + manual object methods) with a unified API for both objects and arrays.Serializer, Validator) without requiring full Symfony installation.Pest/PHPUnit for path-based assertions (e.g., assertEquals($expected, Property::get($obj, 'path'))).getX() chains, Arr::get(), direct properties).benchmark.me or laravel-debugbar).app/Property.php) to abstract Symfony’s API:
namespace App\Property;
use Symfony\Component\PropertyAccess\PropertyAccess;
class Property {
public static function get($object, string $path): mixed {
$accessor = PropertyAccess::createPropertyAccessor();
return $accessor->getValue($object, $path);
}
}
getX() chains).spatie/laravel-data or laravel/serializable-closure.Arr::get()/data_get() logic remains unchanged.Property::get($obj, 'path').symfony/console or symfony/http-client separately.'data.user.profile').Validator for dynamic rules (e.g., ['data.user.age' => 'required|integer']).Property::get($model, 'address.city').spatie/laravel-form-builder for nested fields.getX()->getY())."user.tier.discount").property-access for breaking changes (quarterly updates via Composer).config/property-access.php).PropertyAccessException for Laravel’s error handler (e.g., App\Exceptions\PropertyAccessException)."Path 'user.password' is not allowed").debugbar to log accessed paths in development.'user.address.city' vs. $user->address->city).PropertyAccess instances for repeated use (Symfony supports this via PropertyAccess::createPropertyAccessor()).How can I help you explore Laravel packages today?