Clean up and document code

This commit is contained in:
Franz Liedke 2016-12-28 23:01:49 +01:00
parent 974f45e4e8
commit 8540932638

View File

@ -30,7 +30,10 @@ class CookieFactory
}
/**
* make a new cookie instance.
* Make a new cookie instance.
*
* This method returns a cookie instance for use with the Set-Cookie HTTP header.
* It will be pre-configured according to Flarum's base URL and protocol.
*
* @param string $name
* @param string $value
@ -39,16 +42,13 @@ class CookieFactory
*/
public function make($name, $value = null, $maxAge = null)
{
// Parse the forum's base URL so that we can determine the optimal cookie settings
$url = parse_url(rtrim($this->app->url(), '/'));
$path = array_get($url, 'path') ?: '/';
$secure = array_get($url, 'scheme') === 'https';
return SetCookie::create($name, $value)
->withMaxAge($maxAge)
->withPath($path)
->withSecure($secure)
->withPath(array_get($url, 'path') ?: '/')
->withSecure(array_get($url, 'scheme') === 'https')
->withHttpOnly(true)
->withDomain(null);
}