Skip to content

Add exists() method in PropertyAccesor class #60271

Open
@maixal

Description

@maixal

Description

Hi,

Is it possible to add exists() method in Symfony\Component\PropertyAccess\PropertyAccessor class please ?

Thanks

Example

I use it like this :

private PropertyAccessor $pa;

public function __construct()
{
    $this->pa = PropertyAccess::createPropertyAccessorBuilder()
            ->enableExceptionOnInvalidIndex()
            ->getPropertyAccessor();
}

public function propertyExists(array $objectOrArray, string $propertyPath): bool
    {
        try {
            $this->pa->getValue($objectOrArray, $propertyPath);
            return true;
        } catch(NoSuchIndexException $e) {
            return false;
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions