WebApiExtension icon indicating copy to clipboard operation
WebApiExtension copied to clipboard

WebApiContext::$request and WebApiContext::$response should be protected not private

Open zippy1981 opened this issue 9 years ago • 2 comments

If I want to extend that context I need raw access to the request and response object.

zippy1981 avatar Aug 01 '16 16:08 zippy1981

Take a look at this comment. https://github.com/Behat/WebApiExtension/issues/66#issuecomment-263845309

In fact, this repo needs to remove old version of Guzzle compatibility (the one that it doesn't use PSR-7) to change the visibility of this properties.

kevin-lot avatar Dec 28 '16 14:12 kevin-lot

If you want to get access to the response object without forking this library you can always retrieve it via reflection.

For example, from a sub-class:

protected function getResponse() {
    static $propertyReflection;

    if ($propertyReflection === null) {
        $classReflection    = new ReflectionClass(WebApiContext::class);
        $propertyReflection = $classReflection->getProperty('response');

        $propertyReflection->setAccessible(true);
    }

    return $propertyReflection->getValue($this);
}

You can do something similar to get the request object. This is a bit of a dirty hack, but it gets the result you want.

DanTalash avatar Mar 01 '18 23:03 DanTalash