示例#1
0
 /**
  * Paginate the given query.
  *
  * @param int $perPage
  * @param int $page
  * @param string $pageName
  * @return \Luminous\Bridge\Post\Paginator
  */
 public function paginate($perPage, $page = null, $pageName = 'page')
 {
     $page = $page ?: Paginator::resolveCurrentPage($pageName);
     $query = $this->forPage($page, $perPage)->buildQuery();
     $posts = $this->retrievePosts($query);
     $total = $this->retrieveTotal($query);
     return new Paginator($posts, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
 }
 /**
  * Register the post builder in the container.
  *
  * @return void
  */
 protected function registerPostBuilder()
 {
     $this->app->bind(['Luminous\\Bridge\\Post\\Entities\\AttachmentEntity' => 'wp.post.entities.attachment']);
     $this->app->bind(['Luminous\\Bridge\\Post\\Entities\\HierarchicalEntity' => 'wp.post.entities.page']);
     $this->app->bind(['Luminous\\Bridge\\Post\\Entities\\NonHierarchicalEntity' => 'wp.post.entities.post']);
     Paginator::currentPathResolver(function () {
         return $this->app['request']->url();
     });
     Paginator::currentPageResolver(function ($pageName = 'page') {
         return $this->app['request']->input($pageName);
     });
     $this->app->singleton(PostBuilder::class, function ($app) {
         return new PostBuilder($app);
     });
 }