Skip to content

Commit

Permalink
Moved pagination classes under Grav\Plugin\Pagination namespace, ph…
Browse files Browse the repository at this point in the history
…pstan level 1
  • Loading branch information
mahagr committed Feb 4, 2020
1 parent d6f8961 commit 240fd7b
Show file tree
Hide file tree
Showing 17 changed files with 686 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v1.4.3
## mm/dd/2019

1. [](#new)
* Pass phpstan level 1 tests
* Require Grav v1.6
* Moved pagination classes under `Grav\Plugin\Pagination` namespace

# v1.4.2
## 05/09/2019

Expand Down
2 changes: 2 additions & 0 deletions blueprints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ homepage: https://github.com/getgrav/grav-plugin-pagination
keywords: pagination, plugin, pages, navigation
bugs: https://github.com/getgrav/grav-plugin-pagination/issues
license: MIT
dependencies:
- { name: grav, version: '>=1.6.0' }

form:
validation: strict
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Grav\Plugin;
namespace Grav\Plugin\Pagination;

use Grav\Common\Grav;
use Grav\Common\Iterator;
Expand All @@ -23,8 +23,6 @@ public function __construct(Collection $collection)
{
parent::__construct();

require_once __DIR__ . '/paginationpage.php';

$grav = Grav::instance();

/** @var Uri $uri */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Grav\Plugin;
namespace Grav\Plugin\Pagination;

use Grav\Common\Grav;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace Grav\Plugin;
namespace Grav\Plugin\Pagination;

use \Grav\Common\Grav;
use Grav\Plugin\PaginationPlugin;

class PaginationTwigExtension extends \Twig_Extension
{
Expand Down Expand Up @@ -35,7 +36,8 @@ public function getFunctions()
];
}

public function paginateFunc($collection, $limit, $ignore_url_param_array = []) {
public function paginateFunc($collection, $limit, $ignore_url_param_array = [])
{
$pag = new PaginationPlugin($this, Grav::instance(), $this->config);
$pag->paginateCollection($collection, $limit, $ignore_url_param_array);
}
Expand Down
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "grav-plugin-pagination",
"type": "grav-plugin",
"description": "Pagination plugin for Grav CMS",
"keywords": ["pagination"],
"homepage": "https://github.com/getgrav/grav-plugin-pagination/",
"license": "MIT",
"authors": [
{
"name": "Team Grav",
"email": "[email protected]",
"homepage": "http://getgrav.org",
"role": "Developer"
}
],
"require": {
"php": ">=7.1.3",
"ext-json": "*",
"ext-mbstring": "*"
},
"autoload": {
"psr-4": {
"Grav\\Plugin\\Pagination\\": "classes/plugin"
},
"classmap": ["pagination.php"]
},
"config": {
"platform": {
"php": "7.1.3"
}
}
}
24 changes: 24 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 23 additions & 6 deletions pagination.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php
namespace Grav\Plugin;

use Composer\Autoload\ClassLoader;
use Grav\Common\Page\Collection;
use Grav\Common\Page\Interfaces\PageInterface;
use Grav\Common\Plugin;
use Grav\Plugin\Pagination\PaginationHelper;
use Grav\Plugin\Pagination\PaginationPage;
use Grav\Plugin\Pagination\PaginationTwigExtension;
use RocketTheme\Toolbox\Event\Event;

class PaginationPlugin extends Plugin
Expand All @@ -19,10 +23,23 @@ class PaginationPlugin extends Plugin
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
'onPluginsInitialized' => [
['autoload', 100001],
['onPluginsInitialized', 0]
]
];
}

/**
* [onPluginsInitialized:100000] Composer autoload.
*
* @return ClassLoader
*/
public function autoload()
{
return require __DIR__ . '/vendor/autoload.php';
}

/**
* Initialize configuration
*/
Expand All @@ -33,6 +50,10 @@ public function onPluginsInitialized()
return;
}

class_alias(PaginationHelper::class, 'Grav\\Plugin\\PaginationHelper');
class_alias(PaginationPage::class, 'Grav\\Plugin\\PaginationPage');
class_alias(PaginationTwigExtension::class, 'Grav\\Plugin\\PaginationTwigExtension');

$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
'onPageInitialized' => ['onPageInitialized', 0],
Expand All @@ -53,8 +74,6 @@ public function onTwigTemplatePaths()
*/
public function onTwigExtensions()
{
require_once(__DIR__.'/twig/PaginationTwigExtension.php');

$this->grav['twig']->twig->addExtension(new PaginationTwigExtension());
}

Expand Down Expand Up @@ -96,7 +115,6 @@ public function onCollectionProcessed(Event $event)
}

if (!empty($params['limit']) && $collection->count() > $params['limit']) {
require_once __DIR__ . '/classes/paginationhelper.php';
$this->pagination = new PaginationHelper($collection);
$collection->setParams(['pagination' => $this->pagination]);
}
Expand All @@ -119,14 +137,13 @@ public function onTwigSiteVariables()
* @param int $limit
* @param array $ignore_param_array url parameters to be ignored in page links
*/
public function paginateCollection( $collection, $limit, $ignore_param_array = [])
public function paginateCollection($collection, $limit, $ignore_param_array = [])
{
$collection->setParams(['pagination' => 'true']);
$collection->setParams(['limit' => $limit]);
$collection->setParams(['ignore_params' => $ignore_param_array]);

if ($collection->count() > $limit) {
require_once __DIR__ . '/classes/paginationhelper.php';
$this->pagination = new PaginationHelper($collection);
$collection->setParams(['pagination' => $this->pagination]);

Expand Down
7 changes: 7 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitea591f86e2ec72c59666a51291247f87::getLoader();
Loading

0 comments on commit 240fd7b

Please sign in to comment.