for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Standard representation of any URL that doesn't have a custom builder
*
* @package ElkArte Forum
* @copyright ElkArte Forum contributors
* @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
* @version 2.0 dev
*/
namespace ElkArte\UrlGenerator\Standard;
use ElkArte\UrlGenerator\AbstractUrlGenerator;
* Class Standard
* @package ElkArte\UrlGenerator\Standard
class Standard extends AbstractUrlGenerator
{
/** {@inheritDoc} */
protected $_types = ['standard'];
* {@inheritDoc}
public function generate($params)
return $this->generateQuery($params);
}
protected function generateQuery($params): string
if (!is_array($params))
return '';
$args = [];
foreach ($params as $k => $v)
if (is_int($k))
if ($v === '')
continue;
$args[$k] = $v;
// A substitution token like $1 $2{stuff}, should be left alone
if (is_string($v) && $v !== '')
// A sprintf token (%1$d %2$s etc.) should be left alone, as should
// a substitution token like $1 $2{stuff}
if (($v[0] === '$' && preg_match('~^\$\d({.*})?$~m', $v) !== 0)
|| ($v[0] === '%' && preg_match('~^%\d\$[ds]$~m', $v) !== 0))
$args[$k] = $k . '=' . $v;
if ($v === null)
$args[$k] = $k . '=' . urlencode($v);
$args = $this->getHash($args);
return (!empty($args) ? $this->_separator : '') . implode($this->_separator, $args);