Skip to content

Instantly share code, notes, and snippets.

@matej21
Created March 10, 2014 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matej21/9466767 to your computer and use it in GitHub Desktop.
Save matej21/9466767 to your computer and use it in GitHub Desktop.
<?php
use Nette\Http\Request;
class RefUrlFactory extends Object
{
/** @var \Nette\Http\Url */
protected $fallbackUrl;
/** @var \Nette\Http\Request */
protected $httpRequest;
/**
* @param Url $fallbackUrl
* @param Request $httpRequest
*/
public function __construct($fallbackUrl, Request $httpRequest)
{
$this->fallbackUrl = new \Nette\Http\Url($fallbackUrl);
$this->httpRequest = $httpRequest;
}
/**
* @return \Nette\Http\Url|\Nette\Http\UrlScript
*/
public function create()
{
$url = $this->httpRequest->getUrl();
if (!$url->getHost()) {
$url = $this->fallbackUrl;
}
return $url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment