<commit_before><?php
/**
 * URL helper
 *
 * Provides methods to edit current route and generate corresponding URL
 *
 * PHP Version 5.4.13
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://framework.zend.com/license/new-bsd New BSD License
 */
namespace DoctrineCRUD\View\Helper;

use Zend\View\Helper\AbstractHelper;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
 * URL helper
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://framework.zend.com/license/new-bsd New BSD License
 */
class UrlHelper extends AbstractHelper implements ServiceLocatorAwareInterface
{
    /**
     * Service locator
     *
     * @var \Zend\ServiceManager\ServiceLocatorInterface
     */
    protected $serviceLocator = null;

    /**
     * {@inheritdoc}
     */
    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
    {
        $this->serviceLocator = $serviceLocator;
        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getServiceLocator()
    {
        return $this->serviceLocator->getServiceLocator();
    }

    /**
     * Edits current route match with the given parameters and returns the corresponding URL
     *
     * @param integer $page Page index (starting from 1)
     *
     * @return string
     */
    public function __invoke($page)
    {
        $plugins = $this->getServiceLocator()->get('ControllerPluginManager');
        $routeMatch = $this->getServiceLocator()->get('application')->getMvcEvent()->getRouteMatch();

        return $plugins->get('url')->fromRoute(
            $routeMatch->getMatchedRouteName(),
            $routeMatch->getParams(),
            array(
                'query' => array_merge(
                    $plugins->get('params')->fromQuery(),
                    array('page' => $page)
                ),
            )
        );
    }
}<commit_msg>Improving the URL Helper to inject the page into the route instead of the query string, when possible<commit_after><?php
/**
 * URL helper
 *
 * Provides methods to edit current route and generate corresponding URL
 *
 * PHP Version 5.4.13
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://framework.zend.com/license/new-bsd New BSD License
 */
namespace DoctrineCRUD\View\Helper;

use Zend\View\Helper\AbstractHelper;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
 * URL helper
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://framework.zend.com/license/new-bsd New BSD License
 */
class UrlHelper extends AbstractHelper implements ServiceLocatorAwareInterface
{
    /**
     * Service locator
     *
     * @var \Zend\ServiceManager\ServiceLocatorInterface
     */
    protected $serviceLocator = null;

    /**
     * {@inheritdoc}
     */
    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
    {
        $this->serviceLocator = $serviceLocator;
        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getServiceLocator()
    {
        return $this->serviceLocator->getServiceLocator();
    }

    /**
     * Edits current route match with the given parameters and returns the corresponding URL
     *
     * @param integer $page Page index (starting from 1)
     *
     * @return string
     */
    public function __invoke($page)
    {
        // Get some tools
        $plugins = $this->getServiceLocator()->get('ControllerPluginManager');
        $routeMatch = $this->getServiceLocator()->get('application')->getMvcEvent()->getRouteMatch();

        // Build the appropriate params and options
        $params = $routeMatch->getParams();
        $options = array(
            'query' => $plugins->get('params')->fromQuery(),
        );

        if (array_key_exists('page', $params)) {
            $params['page'] = $page;
        } else {
            $options['query']['page'] = $page;
        }

        // Generate the URL
        return $plugins->get('url')->fromRoute($routeMatch->getMatchedRouteName(), $params, $options);
    }
}
{'fraction_non_alphanumeric': 0.12804128778569673, 'fraction_numerical': 0.002457606291472106, 'mean_word_length': 2.6600719424460433, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1203544', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1119, 'n_words': 257}