<commit_before><?php

/**
 * This file is part of the Krystal Framework
 * 
 * Copyright (c) 2015 <NAME> <<EMAIL>>
 * 
 * For the full copyright and license information, please view
 * the license file that was distributed with this source code.
 */

namespace Krystal\Db\Filter;

final class FilterInvoker implements FilterInvokerInterface
{
	const FILTER_PARAM_PAGE = 'page';
	const FILTER_PARAM_DESC = 'desc';
	const FILTER_PARAM_SORT = 'sort';
	const FILTER_PARAM_NS = 'filter';

	/**
	 * Query data
	 * 
	 * @var array
	 */
	private $input = array();

	/**
	 * Target route
	 * 
	 * @var string
	 */
	private $route;

	/**
	 * State initialization
	 * 
	 * @param array $input Query data
	 * @param string $route
	 * @return void
	 */
	public function __construct(array $input, $route)
	{
		$this->input = $input;
		$this->route = $route;
	}

	/**
	 * Invokes a filter
	 * 
	 * @param \Krystal\Db\Filter\FilterableServiceInterface $service
	 * @param integer $perPageCount Amount of items to be display per page
	 * @return void
	 */
	public function invoke(FilterableServiceInterface $service, $perPageCount)
	{
		if ($this->hasQueryVals()) {

			$page = $this->getPageNumber();
			$sort = $this->getSortingColumn();
			$desc = $this->getDesc();

			$records = $service->filter($this->getData(), $page, $perPageCount, $sort, $desc);

			// Now alter paginator's state
			$paginator = $service->getPaginator();
			$paginator->setUrl($this->getPaginationUrl($page, $sort, $desc));<commit_msg>Added addition check before calling getPaginator()<commit_after><?php

/**
 * This file is part of the Krystal Framework
 * 
 * Copyright (c) 2015 <NAME> <<EMAIL>>
 * 
 * For the full copyright and license information, please view
 * the license file that was distributed with this source code.
 */

namespace Krystal\Db\Filter;

use Krystal\Paginate\PaginatorInterface;

final class FilterInvoker implements FilterInvokerInterface
{
	const FILTER_PARAM_PAGE = 'page';
	const FILTER_PARAM_DESC = 'desc';
	const FILTER_PARAM_SORT = 'sort';
	const FILTER_PARAM_NS = 'filter';

	/**
	 * Query data
	 * 
	 * @var array
	 */
	private $input = array();

	/**
	 * Target route
	 * 
	 * @var string
	 */
	private $route;

	/**
	 * State initialization
	 * 
	 * @param array $input Query data
	 * @param string $route
	 * @return void
	 */
	public function __construct(array $input, $route)
	{
		$this->input = $input;
		$this->route = $route;
	}

	/**
	 * Invokes a filter
	 * 
	 * @param \Krystal\Db\Filter\FilterableServiceInterface $service
	 * @param integer $perPageCount Amount of items to be display per page
	 * @return void
	 */
	public function invoke(FilterableServiceInterface $service, $perPageCount)
	{
		if ($this->hasQueryVals()) {

			$page = $this->getPageNumber();
			$sort = $this->getSortingColumn();
			$desc = $this->getDesc();

			$records = $service->filter($this->getData(), $page, $perPageCount, $sort, $desc);

			// Tweak pagination if available
			if (method_exists($service, 'getPaginator')) {
				$paginator = $service->getPaginator();

				if ($paginator instanceof PaginatorInterface) {
					$paginator->setUrl($this->getPaginationUrl($page, $sort, $desc));
				}
			}
{'fraction_non_alphanumeric': 0.13761755485893418, 'fraction_numerical': 0.0025078369905956114, 'mean_word_length': 3.734421364985163, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, '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': '516656', 'n_tokens_mistral': 1117, 'n_tokens_neox': 987, 'n_words': 279}