Platformsh\Cli\Api::getNestedProperty PHP Method

getNestedProperty() public static method

Get a nested property of a resource, via a dot-separated string path.
public static getNestedProperty ( Platformsh\Client\Model\Resource $resource, string $propertyPath, boolean $lazyLoad = true ) : mixed
$resource Platformsh\Client\Model\Resource
$propertyPath string
$lazyLoad boolean
return mixed
    public static function getNestedProperty(ApiResource $resource, $propertyPath, $lazyLoad = true)
    {
        if (!strpos($propertyPath, '.')) {
            return $resource->getProperty($propertyPath, true, $lazyLoad);
        }
        $parents = explode('.', $propertyPath);
        $propertyName = array_shift($parents);
        $property = $resource->getProperty($propertyName, true, $lazyLoad);
        if (!is_array($property)) {
            throw new \InvalidArgumentException(sprintf('Invalid path "%s": the property "%s" is not an array.', $propertyPath, $propertyName));
        }
        $value = Util::getNestedArrayValue($property, $parents, $keyExists);
        if (!$keyExists) {
            throw new \InvalidArgumentException('Property not found: ' . $propertyPath);
        }
        return $value;
    }