Get results by page
TODO Make this more efficient
@param array $args
489613
public static function getPageCount($args = array())
    {
        $instance = Post\Factory::create(get_called_class());

        $posts_per_page = $instance->getPostsPerPage();
        $criteria = array(
            'post_type'=>$instance->getPostType(),
            'posts_per_page'=>-1
        );
        $criteria = array_merge($criteria, $args);

        $query = new \WP_Query($criteria);
        $n = 0;
        while ($query->have_posts()) {
            $n++;
            $query->next_post();
        }

        return ceil($n / $posts_per_page);
    }
191231
private function _parseArgs(array $args)
	{
		$arg = '';
		if(count($args) > 0)
		{
			foreach($args as $number => $argument)
			{
				if($number === 0)
				{
					$arg .= $argument;
				}
				else
				{
					$arg .= ', ' . $argument;
				}
			}
		}

		return $arg;
	}
470483
public function url( array $args = [] ) {
		$url = get_permalink( $this->ID );
		if ( $args ) {
			$url = add_query_arg( $args, $url );
		}

		return $url;

	}
156123
public function url( array $args = []) {
		$url = get_term_link( $this->term );
		if ( $args ) {
			$url = add_query_arg( $args, $url );
		}

		return $url;
	}
722812
protected function parseArguments(array $args)
    {
        if (count($args) === 1 && is_array($args[0])) {
            $args = $args[0];
        }

        if (count($args) === 0) {
            throw new QueryException('No arguments given');
        }

        return $args;
    }
922917
public function handlePagination($args)
    {
        $uri = $args['uri'];
        $current = $args['current'];
        $total = $args['total'];
        $limit = $args['limit'];

        $uri   = preg_replace('/offset=([0-9]+)/', '', $uri);
        $pages = ceil($total / $limit);
        $page  = $current;

        if ($pages < 2) {
            return;
        }

        $start = 1;

        if ($page >= 3) {
            $start = $page - 2;
        }

        $rtn = '<ul class="pagination">';

        $rtn .= $this->getPaginationPrevLink($page, $uri);

        for ($i = 0; $i < 5 && ($start + $i) <= $pages; $i++) {
            $num = $start + $i;
            $cls = ($page == $num ? 'active' : '');
            $rtn .= '<li class="' . $cls . '"><a href="' . $uri . 'p=' . $num . '">' . $num . '</a></li>';
        }

        $rtn .= $this->getPaginationNextLink($page, $uri, $pages);

        $rtn .= '</ul>';

        return $rtn;
    }
593130
public function fetchAll($as = 'array', $arguments = '')
    {

        $rows = array();
        $style = array(
            "array" => "fetchAssoc",
            "numeric" => "fetch",
            "object" => "fetchObject"
        );

        $as = !array_key_exists((string)$as, $style) ? "array" : (string)$as;

        //Getting all as an array
        while ($row = $this->$style[$as]($arguments)) {
            $rows[] = $row;
        }

        //Return the resultset;
        return $rows;
    }
345993
public function output($args = null) {
        $i = 0;
        foreach ($this->jobs as $job)
            if($job['function']($job['msg']) === TRUE)
                $i++;

        $this->jobs = [];
        return $i;
    }
539939
public function run(array $args)
    {
        print PHP_EOL;

        $command = 'help';

        //as in 'eve generate'
        if(isset($args[1])) {
            $command = $args[1];
        }

        $class = '\\Eve\\Framework\\Cli\\'.ucwords($command);

        if(!class_exists($class)) {
            self::error('No such command `'.$command.'` found.');
        }

        array_shift($args);
        $runner = new $class($this->cwd);

        $results = $runner->run($args);

        print PHP_EOL;

        return $results;
    }
1236845
public function input($arg,...$args){
        /** $args != null */
        if($args) {
            if(is_array($args[0])) {
                //$this->input('get',['name','pass']);
                $args = [$arg,$args[0]];
            }
            else {
                //$this->input('name','pass');
                array_unshift($args,$arg);
                $args = [$this->method,$args];
            }
        }
        else {
            /** $args == null */
            //$this->input('name');
            //$this->input(['name','pass']);
            $args = [$this->method,$arg];
        }

        $input = call_user_func_array([$this,'form'],$args);

        if(is_array($input) === false) {
            return null;
        }

        if(count($input) == 1) {
            return current($input);
        }

        return array_values($input);
    }
1346734
protected function parseArgs($args)
    {
        if (!is_array($args)) {
            return $args;
        }

        $this->silent = in_array('--silent', $args);
        if ($this->silent) {
            $args = array_values(array_diff($args, ['--silent']));
        }

        return $args;
    }
16091
public function all(array $args = []): array
    {
        // Establish args.

        $default_args = [
            // Unique.
            'max'         => PHP_INT_MAX,
            'fail_on_max' => false,

            // Also used by {@link total()}.
            'filters' => [
                'orderby' => 'display_name',
            ],
            'no_cache' => false,
        ];
        $args = array_merge($default_args, $args);
        $args = array_intersect_key($args, $default_args);

        // Unique.
        $args['max']         = max(1, (int) $args['max']);
        $args['fail_on_max'] = (bool) $args['fail_on_max'];

        // Also used by {@link total()}.
        $args['filters']  = (array) $args['filters'];
        $args['no_cache'] = (bool) $args['no_cache'];

        // Check cache; already did this query?

        $cache_keys = $args; // Keys to consider when checking the cache.
        unset($cache_keys['no_cache']); // Cache key exclusions.

        if (($users = &$this->cacheKey(__FUNCTION__, $cache_keys)) !== null && !$args['no_cache']) {
            return $users; // Already cached this.
        }
        // Automatically fail if there are too many; when/if desirable.

        if ($args['fail_on_max'] && $this->total($args) > $args['max']) {
            return $users = []; // Fail; too many.
        }
        // Return the array of all user objects now.

        $WP_User_Query = new \WP_User_Query(array_merge($args['filters'], [
            'fields' => 'all_with_meta', 'offset' => 0, 'paged' => 1, 'number' => -1, 'count_total' => true,
        ]));
        return $users = $WP_User_Query->get_results();
    }
999499
protected function handleValues(array $args)
    {
        if (\count($args) === 1) {
            $values = $args[0];
        } else {
            $values = [];

            foreach ($args as $i => $arg) {
                $values['Value ' . ($i + 1)] = $arg;
            }
        }

        return $values;
    }
797626
public function show(...$args)
    {
        // We need to do this in order to support multiple parameter resource routes. For example,
        // if we map route /user/{user}/comments/{comment} to a controller, Laravel will pass `user`
        // as first argument and `comment` as last argument. So, id object that we want to fetch
        // is the last argument.
        $id = last(func_get_args());

        $this->validate();

        $results = $this->parseRequest()
            ->addIncludes()
            ->addKeyConstraint($id)
            ->modify()
            ->getResults(true)
            ->first()
            ->toArray();

        $meta = $this->getMetaData(true);

        return ApiResponse::make(null, $results, $meta);
    }
375461
public function run(array $args, $method='get'){
      $method = strtolower($method);
      $append_echoed_text = Options::get('core.route.append_echoed_text',true);
      static::trigger('start', $this, $args, $method);

      // Call direct befores
      if ( $this->befores ) {
        // Reverse befores order
        foreach (array_reverse($this->befores) as $mw) {
          static::trigger('before', $this, $mw);
          Event::trigger('core.route.before', $this, $mw);
          ob_start();
          $mw_result  = call_user_func($mw);
          $raw_echoed = ob_get_clean();
          if ($append_echoed_text) Response::add($raw_echoed);
          if ( false  === $mw_result ) {
            return [''];
          } else {
            Response::add($mw_result);
          }
        }
      }

      $callback = (is_array($this->callback) && isset($this->callback[$method]))
                  ? $this->callback[$method]
                  : $this->callback;

      if (is_callable($callback) || is_a($callback, "View") ) {
        Response::type( Options::get('core.route.response_default_type', Response::TYPE_HTML) );

        ob_start();
        if (is_a($callback, "View")) {
          // Get the rendered view
          $view_results = (string)$callback;
        } else {
          $view_results = call_user_func_array($callback, $args);
        }
        $raw_echoed   = ob_get_clean();

        if ($append_echoed_text) Response::add($raw_echoed);
        Response::add($view_results);
      }

      // Apply afters
      if ( $this->afters ) {
        foreach ($this->afters as $mw) {
          static::trigger('after', $this, $mw);
          Event::trigger('core.route.after', $this, $mw);
          ob_start();
          $mw_result  = call_user_func($mw);
          $raw_echoed = ob_get_clean();
          if ($append_echoed_text) Response::add($raw_echoed);
          if ( false  === $mw_result ) {
            return [''];
          } else {
            Response::add($mw_result);
          }
        }
      }

      static::trigger('end', $this, $args, $method);
      Event::trigger('core.route.end', $this);

      return [Filter::with('core.route.response', Response::body())];
     }
1018502
public static function getPairs($args = array())
    {
        $terms = static::getWhere($args);
        if (!Arr::iterable($terms)) {
            return array();
        }

        return array_combine(
            Collection::pluck($terms, 'term_id'),
            Collection::pluck($terms, 'name')
        );
    }
471879
public function run(array $args)
    {
        $command = (string)$args[1];
        $this->router->match($command);
        $args = array_slice($args, 2);

        return $this->router->executeCommand($args);
    }