Skip to content

Request: added withUrl() - #69

Open
JanTvrdik wants to merge 1 commit into
nette:masterfrom
JanTvrdik:request_with_url
Open

Request: added withUrl()#69
JanTvrdik wants to merge 1 commit into
nette:masterfrom
JanTvrdik:request_with_url

Conversation

@JanTvrdik

Copy link
Copy Markdown
Contributor

It's often useful (e.g. in tests) to modify URL inside httpRequest. Doing this is really annoying because Request has lot of constructor parameters. The naming (with*) is based on PSR-7.

What do you think about this idea? Tests are currently missing.

@enumag

enumag commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

Can you show an example of a test where you need this? I never needed anything like it, instead it would be really benefitial for my tests if Request would not be a service (and Response as well for that matter).

Also I certainly wouldn't like this method in the IRequest interface.

@fprochazka

Copy link
Copy Markdown
Contributor

@JanTvrdik I like the idea, doing this every time is tedious.

@JanTvrdik

Copy link
Copy Markdown
Contributor Author

instead it would be really benefitial for my tests if Request would not be a service

Feel free to join the relevant discussion.


Can you show an example of a test where you need this?

Sorry, I have a really bad memory. I found the code I have written (6 days ago) and the withUrl method would not help in that case. The reason why I brought it up today is because I was creating a draft for a router where the method would be helpful.

class DevRouter implements Application\IRouter
{
    // *.signaly.cz -> *.signaly.l  
    // *.signaly.cz -> localhost/signaly/www/*
    public function __construct($fromMask, $toMask, Application\IRouter $innerRouter)
    {
        $this->fromMask = $fromMask;
        $this->toMask = $toMask;
        $this->innerRouter = $innerRouter;
    }

    public function match(Nette\Http\IRequest $httpRequest)
    {
        $fixedUrl = $this->transformIn($httpRequest->url);
        $fixedHttpRequest = $httpRequest->withUrl($fixedUrl); // <-- THIS IS THE LINE
        return $this->innerRouter->match($fixedHttpRequest);
    }

    public function constructUrl(Request $appRequest, Nette\Http\Url $refUrl)
    {
        $url = $this->innerRouter->constructUrl($appRequest, $refUrl);
        $fixedUrl = $this->transformOut($url);
        return $fixedUrl;
    }
}

@enumag

enumag commented Aug 9, 2015

Copy link
Copy Markdown
Contributor

In my opinion you should just write a static helper method cloneRequestWithUrl($request, $url) outside of this class.

@dg
dg force-pushed the master branch 7 times, most recently from 1dc599c to f35d20f 比较 November 5, 2015 00:41
@dg
dg force-pushed the master branch 2 times, most recently from 7981e33 to 3fb64f5 比较 July 21, 2016 12:07
@dg
dg force-pushed the master branch 3 times, most recently from b9f06ea to 4f6d6c9 比较 December 20, 2016 14:30
@dg
dg force-pushed the master branch 3 times, most recently from 2ff2f22 to 40175d7 比较 January 9, 2017 19:55
@dg
dg force-pushed the master branch 5 times, most recently from b031216 to 9979093 比较 January 23, 2017 09:20
@dg
dg force-pushed the master branch 2 times, most recently from 7f12fde to 9791354 比较 February 10, 2017 12:57
@dg
dg force-pushed the master branch 2 times, most recently from 51f373c to 69af026 比较 June 13, 2017 09:59
@dg
dg force-pushed the master branch 3 times, most recently from 87fefb5 to 9590f91 比较 July 21, 2017 19:42
@dg
dg force-pushed the master branch 4 times, most recently from 56c2641 to 544d9e6 比较 March 14, 2018 18:37
@dg
dg force-pushed the master branch 17 times, most recently from caa05a6 to 708b922 比较 September 3, 2018 18:51
注册 for free to join this conversation on GitHub. Already have an account? 登录 to comment

标签

None yet

项目

None yet

Development

Successfully merging this pull request may close these issues.

5 participants