Skip to content
Snippets Groups Projects
Commit 4c266e12 authored by Ere Maijala's avatar Ere Maijala Committed by Demian Katz
Browse files

Fix url helper to work also in console applications. (#1416)

parent f100077c
Branches
Tags
No related merge requests found
......@@ -52,7 +52,7 @@ class Url extends \Zend\View\Helper\Url
*
* @param Request $request Request object for GET parameters
*/
public function __construct(Request $request)
public function __construct(Request $request = null)
{
$this->request = $request;
}
......@@ -95,7 +95,8 @@ class Url extends \Zend\View\Helper\Url
*/
public function addQueryParameters($params, $reuseMatchedParams = true)
{
$requestQuery = $this->request->getQuery()->toArray();
$requestQuery = (null !== $this->request)
? $this->request->getQuery()->toArray() : [];
$options = ['query' => array_merge($requestQuery, $params)];
return $this->__invoke(null, [], $options, $reuseMatchedParams);
}
......
......@@ -59,7 +59,11 @@ class UrlFactory implements FactoryInterface
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
$helper = new $requestedName($container->get('Request'));
$request = $container->get('Request');
if (!($request instanceof \Zend\Http\PhpEnvironment\Request)) {
$request = null;
}
$helper = new $requestedName($request);
$helper->setRouter($container->get('HttpRouter'));
$match = $container->get('Application')
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment