Nelmio\Alice\PropertyAccess\StdPropertyAccessor::getValue PHP Method

getValue() public method

public getValue ( $objectOrArray, $propertyPath )
    public function getValue($objectOrArray, $propertyPath)
    {
        if (false === $objectOrArray instanceof \stdClass) {
            return $this->decoratedPropertyAccessor->getValue($objectOrArray, $propertyPath);
        }
        if (false === isset($objectOrArray->{$propertyPath})) {
            throw NoSuchPropertyExceptionFactory::createForUnreadablePropertyFromStdClass($propertyPath);
        }
        return $objectOrArray->{$propertyPath};
    }

Usage Example

Example #1
0
 public function testGetValueWithTheDecoratedAccessorWhenTheObjectIsNotAnInstanceOfStdClass()
 {
     $object = new DummyWithPublicProperty();
     $property = 'val';
     $object->{$property} = $expected = 'bar';
     $decoratedAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
     $decoratedAccessorProphecy->getValue($object, $property)->will(function ($args) {
         return $args[0]->{$args[1]};
     });
     /** @var PropertyAccessorInterface $decoratedAccessor */
     $decoratedAccessor = $decoratedAccessorProphecy->reveal();
     $accessor = new StdPropertyAccessor($decoratedAccessor);
     $actual = $accessor->getValue($object, $property);
     $this->assertEquals($expected, $actual);
     $decoratedAccessorProphecy->getValue(Argument::cetera())->shouldHaveBeenCalledTimes(1);
 }