Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presenter: removed static from refUrl variable #80

Merged
merged 1 commit into from
Jul 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ abstract class Presenter extends Control implements Application\IPresenter
/** @var ITemplateFactory */
private $templateFactory;

/** @var Nette\Http\Url */
private $refUrlCache;


public function __construct()
{
Expand Down Expand Up @@ -973,9 +976,9 @@ protected function createRequest($component, $destination, array $args, $mode)
}

// CONSTRUCT URL
static $refUrl;
$refUrl = $this->refUrlCache;
if ($refUrl === NULL) {
$refUrl = new Http\Url($this->httpRequest->getUrl());
$this->refUrlCache = $refUrl = new Http\Url($this->httpRequest->getUrl());
$refUrl->setPath($this->httpRequest->getUrl()->getScriptPath());
}
if (!$this->router) {
Expand Down
56 changes: 56 additions & 0 deletions tests/Application/Presenter.twoDomains.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* Test: Nette\Application\UI\Presenter::link()
*/

use Nette\Http,
Nette\Application,
Tester\Assert;


require __DIR__ . '/../bootstrap.php';


class TestPresenter extends Application\UI\Presenter
{

protected function createTemplate($class = NULL)
{
}

}

class MockPresenterFactory extends Nette\Object implements Nette\Application\IPresenterFactory
{
function getPresenterClass(& $name)
{
return str_replace(':', 'Module\\', $name) . 'Presenter';
}

function createPresenter($name)
{}
}

function testLink($domain)
{
$url = new Http\UrlScript('http://' . $domain . '/index.php');
$url->setScriptPath('/index.php');

$presenter = new TestPresenter;
$presenter->injectPrimary(
NULL,
new MockPresenterFactory,
new Application\Routers\SimpleRouter,
new Http\Request($url),
new Http\Response
);

$request = new Application\Request('Test', Http\Request::GET, []);
$presenter->run($request);

Assert::same( 'http://' . $domain . '/index.php?action=default&presenter=Test', $presenter->link('//this') );
}

testLink('first.localhost');
testLink('second.localhost');