Paginate request.

@param  mixed  $modelClass
@param  string $method
@param  array  $params
@return \Illuminate\Pagination\LengthAwarePaginator
355876
public function paginateChildren($modelClass, $method, array $params = [])
    {
        // Set request params
        $params = array_filter(array_merge([
            'page' => 1
        ], $params));

        // Make request
        $result = $this->makeRequest($this->getEndpoint(), $method, [$this->getKey(), $params]);

        // Hydrate object
        $result = $this->paginateHydrate($result, $modelClass);

        // Append search params
        $result->appends($params);

        return $result;
    }
151409
protected function forward($callback, $method, $params = [])
    {
        if ($this->isLoaded()) {
            if (!$this->soft) {
                $oldInstance = clone $this->instance;
            }
            $return = $callback();
            if (!$this->soft && $oldInstance != $this->instance) {
                $this->instance = $oldInstance;
                $this->throwImmutableException();
            }
            return $return;
        } else {
            return parent::$method($params);
        }
    }
1001758
public function paginate($perPage = null, $columns = ['*'])
    {
        $total = $this->query->getCountForPagination();

        $this->query->forPage(
            $page = Paginator::resolveCurrentPage(),
            $perPage = $perPage ?: $this->entityMap->getPerPage()
        );

        return new LengthAwareEntityPaginator($this->get($columns)->all(), $total, $perPage, $page, [
            'path' => Paginator::resolveCurrentPath(),
        ]);
    }
80476
protected function invoke($method, array $params = [])
    {
        $qualifiedClassName = get_class($this);

        if (false !== $pos = strrpos($qualifiedClassName, '\\')) {
            $methodRef = substr($qualifiedClassName, $pos + 1) . ':' . $method;
        } else {
            $methodRef = $qualifiedClassName . ':' . $method;
        }

        $invoker = $this->user->getInvoker();

        return $invoker(function () use ($methodRef, $method, $params) {
            $this->dispatcher->dispatch(
                Events::BEFORE_REQUEST,
                new PreCallEvent($methodRef, $params, $this->user)
            );

            try {
                $response = $this->__soapCall($method, $params);
            } catch (\Exception $ex) {
                if ($ex instanceof \SoapFault) {
                    if (strtolower($ex->faultcode) === 'http') {
                        $ex = new NetworkException($ex->getMessage(), 0, $ex);
                    } else {
                        $ex = $this->handleFault($ex, $methodRef, $params);
                    }
                }

                $this->dispatcher->dispatch(
                    Events::FAIL_REQUEST,
                    new FailCallEvent($methodRef, $params, $this->user, $this, $ex, $this->fetchUtits())
                );

                throw $ex;
            }

            $this->dispatcher->dispatch(
                Events::AFTER_REQUEST,
                new PostCallEvent($methodRef, $params, $this->user, $this, $response, $this->fetchUtits())
            );

            return $response;
        });
    }
1114363
public function request($method, array $params = []) {
        $data = [
            'version' => '2.0',
            'method' => $method,
            'params' => $params,
            'id' => $this->genID()
        ];

        $data['params']['apikey'] = $this->config[self::KEY];

        if (array_key_exists(self::LANGUAGE, $this->config) &&
            !array_key_exists(self::LANGUAGE, $params)) {
            $data['params'][self::LANGUAGE] = $this->config[self::LANGUAGE];
        }

        $response = $this->execute($data);

        $this->evaluateResponse($response);

        return $response['result'];
    }
588637
public function callAction($method, $parameters)
	{
		$response = $this->response();
		$action_response = parent::callAction($method, $parameters);
		
		switch (true) {
			case $action_response instanceof Model:
				$response->setContent(Api::transform($action_response));
				break;
				
			case $action_response instanceof Collection:
				$output = array();
				foreach ($action_response as $model) {
					$output[] = Api::transform($model);
				}
				
				$response->setContent($output);
				break;
				
			case $action_response instanceof Paginator:
				$output = array();
				foreach ($action_response->getCollection() as $model) {
					$output[] = Api::transform($model);
				}
				
				$response->setContent($output)
					->header('Pagination-Page', $action_response->currentPage())
					->header('Pagination-Num', $action_response->perPage())
					->header('Pagination-Total', $action_response->total())
					->header('Pagination-Last-Page', $action_response->lastPage());
				break;
				
			case $action_response instanceof Response:
				$response = $action_response;
				break;
				
			default:
				$response->setContent($action_response);
		}
		
		return $response;
	}
1039783
public static function bcRun($class, $method, array $params, $implementation, array $filters) {
		$implementation = static::_bcImplementation($class, $method, $params, $implementation);
		$ids = static::_ids($class, $method);

		foreach ($ids as $id) {
			if (isset(static::$_filters[$id])) {
				$filters = array_merge(static::$_filters[$id], $filters);
			}
		}
		return new Chain(compact('class', 'method', 'filters'));
	}
114925
public function paginate(Paginator $paginator, $params = [])
    {
        $query = $this->paramsToQuery($params);

        $countQuery = $this->getDB()->newSelect();
        $countQuery->count(['*', 'count']);
        $countQuery->from([$query, 'tbl']);
        $results = $countQuery->execute()->fetchResults();
        $count = $results[0]['count'];

        $paginator->setCount($count);

        $params['limit'] = $paginator->getLimits();

        return $this->findByParams($params);
    }
1244851
public function request($method, $params = [])
    {
        $response = $this->client->post($this->getUrl($method), ['query' => $params]);

        if ($response->getStatusCode() === 200) {
            return (string)$response->getBody();
        } else {
            throw new Exception(sprintf('Sms.ru problem. Status code is %s', $response->getStatusCode()), $response->getStatusCode());
        }
    }
151885
private function invokeClassMethod($class, $method, $namedParams, $classParams)
    {
        if (!class_exists($class)) {
            throw new \InvalidArgumentException("Class $class does not exist.");
        }

        $object = new $class();

        return $this->invokeObjectMethod($object, $method, $namedParams, $classParams);
    }
1164816
public function paginateHydrate($result, $modelClass = null)
    {
        // Get values
        $pagination = array_get($result, 'pagination', []);
        $items = array_get($result, 'items', []);
        $page = LengthAwarePaginator::resolveCurrentPage();

        // Set pagination
        $perPage = array_get($pagination, 'perPage', array_get($pagination, 'per_page', 15));
        $total = array_get($pagination, 'total', null);

        // Set options
        $options = is_array($result) ? array_except($result, [
            'pagination',
            'items',
            'next',
            'per_page',
            'last'
        ]) : [];

        return new LengthAwarePaginator($this->hydrate($items, $modelClass), $total, $perPage, $page,
            array_merge($options, [
                'path' => LengthAwarePaginator::resolveCurrentPath()
            ]));
    }
363291
public function search($params, $models)
    {
        $dataProvider = new ArrayDataProvider([
            'allModels' => $models,
            'pagination' => false,
            'sort' => [
                'attributes' => ['duration', 'seq', 'type', 'method', 'request'],
                'defaultOrder' => [
                    'duration' => SORT_DESC,
                ],
            ],
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $filter = new Filter();
        $this->addCondition($filter, 'type', true);
        $this->addCondition($filter, 'method', true);
        $this->addCondition($filter, 'request', true);
        $dataProvider->allModels = $filter->filter($models);

        return $dataProvider;
    }
1084459
public function silentRequest($method, array $params = []) {
    $response = NULL;

    if (!method_exists($this, $method)) {
      throw new \InvalidArgumentException("Method {$method} doesn't exist.");
    }

    $this->turnRouteEventsOff();

    try {
      $response = call_user_func_array([$this, $method], $params);
    }
    catch (\Exception $e) {
      $mesg = sprintf(
        'Silent exception during %s request: (%d) - %s',
        $method,
        $e->getCode(),
        $e->getMessage()
      );

      $this->logger->error($mesg);
    }

    $this->turnRouteEventsOn();

    return $response;
  }
560751
public function paginate(array $params)
    {

        // page
        if (isset($params[$this->getParamPage()])) {
            $this->setPage($params[$this->getParamPage()]);
        }

        return $this;
    }
271091
protected function newQuery(array $options = array(), $modelClass = null)
    {
        $options = array_replace(array(
            'includes' => array(),
            'order_by' => array(),
            'where'    => array(),
            'has'      => array(), // relationships
        ), $options);

        if (!is_string($modelClass)) {
            $modelClass = $this->modelClass;
        }
        $query = call_user_func(array(new $modelClass(), 'newQuery'));

        /*
         * Includes
         */
        if (is_array($options['includes'])) {
            $includes = array_values($options['includes']);

            foreach ($includes as $include) {
                if (in_array($include, $this->includableRelationships)) {
                    $query->with($include);
                }
            }
        }

        /*
         * Where
         */
        if (is_array($options['where'])) {
            foreach ($options['where'] as $condition) {
                if (
                    is_array($condition)
                    && count($condition) == 3
                ) {
                    $query->where($condition[0], $condition[1], $condition[2]);
                }
            }
        }

        /*
         * Has
         */
        if (is_array($options['has'])) {
            foreach ($options['has'] as $relation => $conditions) {
                if (
                    is_string($relation)
                    && is_array($conditions)
                ) {
                    $query->whereHas($relation, function ($q) use ($conditions) {
                        $i = 0;
                        foreach ($conditions as $condition) {
                            if (
                                is_array($condition)
                                && count($condition) == 2
                            ) {
                                // TODO: our goal is to reduce the subcondition, e.g.:
                                // select * from `categories` where (select count(*) from `category_translations` where `category_translations`.`category_id` = `categories`.`id` and (`slug` = "men" or `slug` = "shoes")) >= 1
                                // current implementation is missing the "()" between the `slug` condition, like this:
                                // select * from `categories` where (select count(*) from `category_translations` where `category_translations`.`category_id` = `categories`.`id` and `slug` = "men" and `slug` = "shoes") >= 1
                                // obviously, not the same result
                                // if( $i == 0 )
                                // {
                                    $q->where($condition[0], $condition[1]);
                                // }
                                // else
                                // {
                                //     $q->orWhere($condition[0], $condition[1]);
                                // }

                                // ++$i;
                            }
                        }
                    });
                }
            }
        }

        /*
        * orders
        */
        if (is_string($options['order_by'])) {
            $options['order_by'] = json_decode($options['order_by'], true);
        }
        if (is_array($options['order_by'])) {
            foreach ($options['order_by'] as $field => $direction) {
                $direction = strtoupper($direction);

                // TODO implement orderableFields
                if (
                    is_string($field)
                    && in_array($direction, array('ASC', 'DESC'))
                    // && in_array($field, $this->orderableFields)
                ) {
                    $query->orderBy($field, $direction);
                }
            }
        }

        return $query;
    }
870098
public function create($method, $params)
    {
        if (strtolower($method) == 'get') {
            $this->get = $params;
        } else {
            $this->post = $params;
        }
        return $this;
    }
467651
public function invoke(FilterableServiceInterface $service, $perPageCount, array $parameters = array())
    {
        $page = $this->getPageNumber();
        $sort = $this->getSortingColumn();
        $desc = $this->getDesc();

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

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

            if ($paginator instanceof PaginatorInterface) {
                $paginator->setUrl($this->getPaginationUrl($page, $sort, $desc));
            }
        }

        return $records;
    }