diff --git a/.travis.yml b/.travis.yml index e9c8a8b..4ef22e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ sudo: required language: php php: - - 7.1 - 7.2 - 7.3 diff --git a/composer.json b/composer.json index 3497780..e29ab4d 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": "~7.1.0|~7.2.0|~7.3.0", + "php": "~7.2.0|~7.3.0", "ext-pcntl": "*", "symfony/dependency-injection": "^3.3", "symfony/config": "^3.3", @@ -32,7 +32,9 @@ "symfony/property-info": "^4.3", "doctrine/annotations": "^1.8", "ramsey/uuid": "^3.8", - "webgriffe/amp-elasticsearch": "^1.1" + "webgriffe/amp-elasticsearch": "^1.1", + "pagerfanta/pagerfanta": "^2.3", + "symfony/deprecation-contracts": "^2.1" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index fec76a6..81ed853 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,3 +4,4 @@ parameters: - '/Method Webgriffe\\Esb\\FlowExtension::getNamespace\(\) should return string but returns false\./' - '/Method Webgriffe\\Esb\\FlowExtension::getXsdValidationBasePath\(\) should return string but returns false\./' - '/Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::useAttributeAsKey\(\)\./' + - '/Webgriffe\\Esb\\Console\\Pager\\AsyncPager::__construct\(\) does not call parent constructor from Pagerfanta\\Pagerfanta\./' diff --git a/src/Console/Pager/AmpElasticsearchUriSearchAdapter.php b/src/Console/Pager/AmpElasticsearchUriSearchAdapter.php index 266e193..4790834 100644 --- a/src/Console/Pager/AmpElasticsearchUriSearchAdapter.php +++ b/src/Console/Pager/AmpElasticsearchUriSearchAdapter.php @@ -1,5 +1,7 @@ adapter = $adapter; @@ -124,9 +135,7 @@ public function getNormalizeOutOfRangePages() private function filterBoolean($value) { - if (!is_bool($value)) { - throw new NotBooleanException(); - } + Assert::boolean($value); return $value; } @@ -140,7 +149,7 @@ private function filterBoolean($value) * * @return self * - * @throws NotIntegerMaxPerPageException If the max per page is not an integer even converting. + * @throws NotValidMaxPerPageException If the max per page is not an integer even converting. * @throws LessThan1MaxPerPageException If the max per page is less than 1. */ public function setMaxPerPage($maxPerPage) @@ -162,7 +171,7 @@ private function filterMaxPerPage($maxPerPage) private function checkMaxPerPage($maxPerPage) { if (!is_int($maxPerPage)) { - throw new NotIntegerMaxPerPageException(); + throw new NotValidMaxPerPageException(); } if ($maxPerPage < 1) { @@ -195,7 +204,7 @@ public function getMaxPerPage() * * @return self * - * @throws NotIntegerCurrentPageException If the current page is not an integer even converting. + * @throws NotValidCurrentPageException If the current page is not an integer even converting. * @throws LessThan1CurrentPageException If the current page is less than 1. * @throws OutOfRangeCurrentPageException If It is not allowed out of range pages and they are not normalized. */ @@ -250,7 +259,7 @@ private function filterCurrentPage($currentPage) private function checkCurrentPage($currentPage) { if (!is_int($currentPage)) { - throw new NotIntegerCurrentPageException(); + throw new NotValidCurrentPageException(); } if ($currentPage < 1) { @@ -534,9 +543,7 @@ private function needsToIntegerConversion($value) */ public function getPageNumberForItemAtPosition($position) { - if (!is_int($position)) { - throw new NotIntegerException(); - } + Assert::integer($position); if ($this->getNbResults() < $position) { throw new \OutOfBoundsException(sprintf( diff --git a/src/Console/Pager/AsyncPagerAdapterInterface.php b/src/Console/Pager/AsyncPagerAdapterInterface.php index 3376c65..1412b53 100644 --- a/src/Console/Pager/AsyncPagerAdapterInterface.php +++ b/src/Console/Pager/AsyncPagerAdapterInterface.php @@ -18,8 +18,8 @@ public function getNbResults(): Promise; /** * Returns an slice of the results. * - * @param integer $offset The offset. - * @param integer $length The length. + * @param int $offset The offset. + * @param int $length The length. * * @return Promise which resolve array|\Traversable The slice. */ diff --git a/src/Console/Pager/LessThan1CurrentPageException.php b/src/Console/Pager/LessThan1CurrentPageException.php index 27c46c4..3fe5088 100644 --- a/src/Console/Pager/LessThan1CurrentPageException.php +++ b/src/Console/Pager/LessThan1CurrentPageException.php @@ -1,7 +1,19 @@ view = $view; + } + + public function getFunctions() + { + return [ + new TwigFunction('pagerfanta', [$this, 'renderPagerfanta'], ['is_safe' => ['html']]) + ]; + } + + public function renderPagerfanta( + Pagerfanta $pagerfanta, + string $route, + array $options = [] + ): string { + $routeGenerator = function ($page) use ($route): string { + return strtr($route, ['{page}' => $page]); + }; + + return $this->view->render($pagerfanta, $routeGenerator, $options); + } +} diff --git a/src/Console/Resources/config/services.yml b/src/Console/Resources/config/services.yml index 48a1f1a..5f3cb33 100644 --- a/src/Console/Resources/config/services.yml +++ b/src/Console/Resources/config/services.yml @@ -19,12 +19,18 @@ services: console.twig.class_extension: class: \Webgriffe\Esb\Console\ClassTwigExtension + console.twig.pagerfanta_extension: + class: \Webgriffe\Esb\Console\PagerfantaTwigExtension + arguments: + - '@console.pagerfanta.view.bootstrap4' + console.twig: class: \Twig\Environment arguments: - '@console.twig.loader' calls: - ['addExtension', ['@console.twig.class_extension']] + - ['addExtension', ['@console.twig.pagerfanta_extension']] console.server: class: \Webgriffe\Esb\Console\Server @@ -37,3 +43,6 @@ services: calls: - [ setContainer, [ '@service_container' ]] public: true + + console.pagerfanta.view.bootstrap4: + class: \Pagerfanta\View\TwitterBootstrap4View diff --git a/src/Console/Resources/views/flow.html.twig b/src/Console/Resources/views/flow.html.twig index cac250c..78d5003 100644 --- a/src/Console/Resources/views/flow.html.twig +++ b/src/Console/Resources/views/flow.html.twig @@ -58,19 +58,8 @@ {% endif %} - {% if pager.haveToPaginate %} - - {% endif %} +