diff --git a/README.md b/README.md index a181245..d120593 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,32 @@ # PropertyAccessor -## Example - -````PHP -persons; - } -} - -class Person -{ - /** @var Vehicle[] | array */ - public $vehicles; -} +This PropertyAccessor allows you to access properties using getters, issers, and hassers, +or directly if the property is public. -class Vehicle -{ - /** @var string */ - private $licensePlate; - - (...) - - public function getLicensePlate(): string - { - return $this->licensePlate; - } -} - -$vehicle = new Vehicle('AA-11-BB'); -$person = new Person(); -$person->vehicles = [$vehicle]; -$group = new Group([$person]); +This library also provides a `getAccessMethod` function, which returns a implementation of the `AccessMethodInterface`. +This function tells you how the property will be accessed. +## Example +Value +````PHP $propertyAccessor = new PropertyAccessor(); -$result = $propertyAccessor->getValue('persons[0].vehicles[0].licensePlate', $group); -// Returns 'AA-11-BB' +// Will throw an `NoAccessMethodException` if there is no method to access the property. +$result = $propertyAccessor->getValue('users[0].repositories[0].name', $group); +```` +Access method +````PHP +$accessMethod = $this->propertyAccessor->getAccessMethod('licensePlate', Car::class); + +if ($accessMethod instanceof MethodAccessMethod) { + // The value wil be accessed by a method. + $methodName = $accessMethod->getMethodName(); +} elseif ($accessMethod instanceof ProperyAccessMethod) { + // The value wil be accessed by a (public) property. + $propertyName = $accessMethod->getPropertyName(); +} elseif ($accessMethod === null) { + // No access method found. +} ```` ## Tests