Permalink
Browse files

refactored many things

  • Loading branch information...
pablodip committed Mar 31, 2013
1 parent ae0ff21 commit 103a140c77b40f22b2f413858210d735b9b2daf9
Showing with 2,452 additions and 1,027 deletions.
  1. +3 −2 .gitignore
  2. +1 −2 .travis.yml
  3. +1 −1 composer.json
  4. +1 −1 phpunit.xml.dist
  5. +0 −6 src/Pagerfanta/Adapter/AdapterInterface.php
  6. +0 −6 src/Pagerfanta/Adapter/ArrayAdapter.php
  7. +13 −13 src/Pagerfanta/Adapter/CallbackAdapter.php
  8. +0 −6 src/Pagerfanta/Adapter/DoctrineCollectionAdapter.php
  9. +5 −7 src/Pagerfanta/Adapter/DoctrineODMMongoDBAdapter.php
  10. +0 −6 src/Pagerfanta/Adapter/DoctrineORM/Paginator.php
  11. +4 −9 src/Pagerfanta/Adapter/DoctrineORMAdapter.php
  12. +0 −6 src/Pagerfanta/Adapter/MandangoAdapter.php
  13. +4 −7 src/Pagerfanta/Adapter/MongoAdapter.php
  14. +23 −7 src/Pagerfanta/Adapter/NullAdapter.php
  15. +8 −2 src/Pagerfanta/Adapter/PropelAdapter.php
  16. +63 −16 src/Pagerfanta/Adapter/SolariumAdapter.php
  17. +19 −0 src/Pagerfanta/Exception/NotBooleanException.php
  18. +251 −74 src/Pagerfanta/Pagerfanta.php
  19. +3 −129 src/Pagerfanta/PagerfantaInterface.php
  20. +173 −66 src/Pagerfanta/View/DefaultView.php
  21. +2 −6 src/Pagerfanta/View/OptionableView.php
  22. +89 −0 src/Pagerfanta/View/Template/DefaultTemplate.php
  23. +43 −0 src/Pagerfanta/View/Template/Template.php
  24. +40 −0 src/Pagerfanta/View/Template/TemplateInterface.php
  25. +139 −0 src/Pagerfanta/View/Template/TwitterBootstrapTemplate.php
  26. +9 −96 src/Pagerfanta/View/TwitterBootstrapView.php
  27. +0 −4 src/Pagerfanta/View/ViewFactory.php
  28. +0 −12 src/Pagerfanta/View/ViewFactoryInterface.php
  29. +3 −8 src/Pagerfanta/View/ViewInterface.php
  30. +7 −8 tests/Pagerfanta/Tests/Adapter/ArrayAdapterTest.php
  31. +50 −18 tests/Pagerfanta/Tests/Adapter/CallbackAdapterTest.php
  32. +75 −0 tests/Pagerfanta/Tests/Adapter/DoctrineCollectionAdapterTest.php
  33. +0 −64 tests/Pagerfanta/Tests/Adapter/DoctrineCollectionTest.php
  34. +35 −30 tests/Pagerfanta/Tests/Adapter/DoctrineODMMongoDBAdapterTest.php
  35. +43 −29 tests/Pagerfanta/Tests/Adapter/MandangoAdapterTest.php
  36. +33 −25 tests/Pagerfanta/Tests/Adapter/MongoAdapterTest.php
  37. +21 −11 tests/Pagerfanta/Tests/Adapter/NullAdapterTest.php
  38. +29 −37 tests/Pagerfanta/Tests/Adapter/PropelAdapterTest.php
  39. +26 −0 tests/Pagerfanta/Tests/Adapter/Solarium2AdapterTest.php
  40. +26 −0 tests/Pagerfanta/Tests/Adapter/Solarium3AdapterTest.php
  41. +60 −83 tests/Pagerfanta/Tests/Adapter/SolariumAdapterTest.php
  42. +471 −166 tests/Pagerfanta/Tests/PagerfantaTest.php
  43. +260 −25 tests/Pagerfanta/Tests/View/DefaultViewTest.php
  44. +50 −12 tests/Pagerfanta/Tests/View/OptionableViewTest.php
  45. +297 −27 tests/Pagerfanta/Tests/View/TwitterBootstrapViewTest.php
  46. +72 −0 tests/Pagerfanta/Tests/View/ViewTestCase.php
View
@@ -1,3 +1,4 @@
-phpunit.xml
-/vendor/
composer.lock
+Guardfile
+phpunit.xml
+/vendor/
View
@@ -14,8 +14,7 @@ env:
- DOCTRINE_ORM_VERSION=2.3.*
- DOCTRINE_ORM_VERSION=dev-master
- SOLARIUM_VERSION=2.*
- - SOLARIUM_VERSION=3.0.*
- - SOLARIUM_VERSION=3.1.*
+ - SOLARIUM_VERSION=dev-develop
services: mongodb
View
@@ -18,7 +18,7 @@
"mandango/mandango": "*",
"doctrine/mongodb-odm": "*",
"propel/propel1": "~1.6",
- "solarium/solarium": "3.*"
+ "solarium/solarium": "dev-develop"
},
"minimum-stability": "dev",
"suggest": {
View
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<phpunit bootstrap="tests/bootstrap.php">
+<phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Pagerfanta Test Suite">
<directory>tests/Pagerfanta/</directory>
@@ -15,17 +15,13 @@
* AdapterInterface.
*
* @author Pablo Díez <pablodip@gmail.com>
- *
- * @api
*/
interface AdapterInterface
{
/**
* Returns the number of results.
*
* @return integer The number of results.
- *
- * @api
*/
function getNbResults();
@@ -36,8 +32,6 @@ function getNbResults();
* @param integer $length The length.
*
* @return array|\Traversable The slice.
- *
- * @api
*/
function getSlice($offset, $length);
}
@@ -15,8 +15,6 @@
* ArrayAdapter.
*
* @author Pablo Díez <pablodip@gmail.com>
- *
- * @api
*/
class ArrayAdapter implements AdapterInterface
{
@@ -26,8 +24,6 @@ class ArrayAdapter implements AdapterInterface
* Constructor.
*
* @param array $array The array.
- *
- * @api
*/
public function __construct(array $array)
{
@@ -38,8 +34,6 @@ public function __construct(array $array)
* Returns the array.
*
* @return array The array.
- *
- * @api
*/
public function getArray()
{
@@ -18,39 +18,39 @@
*/
class CallbackAdapter implements AdapterInterface
{
- private $nbResultsCallback;
- private $sliceCallback;
+ private $getNbResultsCallback;
+ private $getSliceCallback;
/**
- * @param callable $nbResultsCallback
- * @param callable $sliceCallback
+ * @param callable $getNbResultsCallback
+ * @param callable $getSliceCallback
*/
- public function __construct($nbResultsCallback, $sliceCallback)
+ public function __construct($getNbResultsCallback, $getSliceCallback)
{
- if (!is_callable($nbResultsCallback)) {
- throw new InvalidArgumentException('$nbResultsCallback should be a callable');
+ if (!is_callable($getNbResultsCallback)) {
+ throw new InvalidArgumentException('$getNbResultsCallback should be a callable');
}
- if (!is_callable($sliceCallback)) {
- throw new InvalidArgumentException('$sliceCallback should be a callable');
+ if (!is_callable($getSliceCallback)) {
+ throw new InvalidArgumentException('$getSliceCallback should be a callable');
}
- $this->nbResultsCallback = $nbResultsCallback;
- $this->sliceCallback = $sliceCallback;
+ $this->getNbResultsCallback = $getNbResultsCallback;
+ $this->getSliceCallback = $getSliceCallback;
}
/**
* {@inheritdoc}
*/
public function getNbResults()
{
- return call_user_func($this->nbResultsCallback);
+ return call_user_func($this->getNbResultsCallback);
}
/**
* {@inheritdoc}
*/
public function getSlice($offset, $length)
{
- return call_user_func_array($this->sliceCallback, array($offset, $length));
+ return call_user_func($this->getSliceCallback, $offset, $length);
}
}
@@ -17,8 +17,6 @@
* DoctrineCollectionAdapter.
*
* @author Pablo Díez <pablodip@gmail.com>
- *
- * @api
*/
class DoctrineCollectionAdapter implements AdapterInterface
{
@@ -28,8 +26,6 @@ class DoctrineCollectionAdapter implements AdapterInterface
* Constructor.
*
* @param Collection $collection A Doctrine collection.
- *
- * @api
*/
public function __construct(Collection $collection)
{
@@ -40,8 +36,6 @@ public function __construct(Collection $collection)
* Returns the collection.
*
* @return Collection The collection.
- *
- * @api
*/
public function getCollection()
{
@@ -17,8 +17,6 @@
* DoctrineODMMongoDBAdapter.
*
* @author Pablo Díez <pablodip@gmail.com>
- *
- * @api
*/
class DoctrineODMMongoDBAdapter implements AdapterInterface
{
@@ -28,8 +26,6 @@ class DoctrineODMMongoDBAdapter implements AdapterInterface
* Constructor.
*
* @param Builder $queryBuilder A DoctrineMongo query builder.
- *
- * @api
*/
public function __construct(Builder $queryBuilder)
{
@@ -40,8 +36,6 @@ public function __construct(Builder $queryBuilder)
* Returns the query builder.
*
* @return Builder The query builder.
- *
- * @api
*/
public function getQueryBuilder()
{
@@ -61,6 +55,10 @@ public function getNbResults()
*/
public function getSlice($offset, $length)
{
- return iterator_to_array($this->queryBuilder->limit($length)->skip($offset)->getQuery()->execute());
+ return $this->queryBuilder
+ ->limit($length)
+ ->skip($offset)
+ ->getQuery()
+ ->execute();
}
}
@@ -23,8 +23,6 @@
*
* @author Pablo Díez <pablodip@gmail.com>
* @author Benjamin Eberlei <kontakt@beberlei.de>
- *
- * @api
*/
class Paginator implements \Countable, \IteratorAggregate
{
@@ -40,8 +38,6 @@ class Paginator implements \Countable, \IteratorAggregate
*
* @param Query|QueryBuilder $query A Doctrine ORM query or query builder.
* @param Boolean $fetchJoinCollection Whether the query joins a collection (true by default).
- *
- * @api
*/
public function __construct($query, $fetchJoinCollection = true)
{
@@ -57,8 +53,6 @@ public function __construct($query, $fetchJoinCollection = true)
* Returns the query
*
* @return Query
- *
- * @api
*/
public function getQuery()
{
@@ -18,8 +18,6 @@
* DoctrineORMAdapter.
*
* @author Christophe Coevoet <stof@notk.org>
- *
- * @api
*/
class DoctrineORMAdapter implements AdapterInterface
{
@@ -31,10 +29,8 @@ class DoctrineORMAdapter implements AdapterInterface
/**
* Constructor.
*
- * @param \Doctrine\ORM\Query|\Doctrine\ORM\QueryBuilder $query A Doctrine ORM query or query builder.
- * @param Boolean $fetchJoinCollection Whether the query joins a collection (true by default).
- *
- * @api
+ * @param \Doctrine\ORM\Query|\Doctrine\ORM\QueryBuilder $query A Doctrine ORM query or query builder.
+ * @param Boolean $fetchJoinCollection Whether the query joins a collection (true by default).
*/
public function __construct($query, $fetchJoinCollection = true)
{
@@ -49,8 +45,6 @@ public function __construct($query, $fetchJoinCollection = true)
* Returns the query
*
* @return Query
- *
- * @api
*/
public function getQuery()
{
@@ -80,7 +74,8 @@ public function getNbResults()
*/
public function getSlice($offset, $length)
{
- $this->paginator->getQuery()
+ $this->paginator
+ ->getQuery()
->setFirstResult($offset)
->setMaxResults($length);
@@ -17,8 +17,6 @@
* MandangoAdapter.
*
* @author Pablo Díez <pablodip@gmail.com>
- *
- * @api
*/
class MandangoAdapter implements AdapterInterface
{
@@ -28,8 +26,6 @@ class MandangoAdapter implements AdapterInterface
* Constructor.
*
* @param Query $query The query.
- *
- * @api
*/
public function __construct(Query $query)
{
@@ -40,8 +36,6 @@ public function __construct(Query $query)
* Returns the query.
*
* @return Query The query.
- *
- * @api
*/
public function getQuery()
{
@@ -15,8 +15,6 @@
* MongoAdapter.
*
* @author Sergey Ponomaryov <serg.ponomaryov@gmail.com>
- *
- * @api
*/
class MongoAdapter implements AdapterInterface
{
@@ -26,8 +24,6 @@ class MongoAdapter implements AdapterInterface
* Constructor.
*
* @param \MongoCursor $cursor The cursor.
- *
- * @api
*/
public function __construct(\MongoCursor $cursor)
{
@@ -38,8 +34,6 @@ public function __construct(\MongoCursor $cursor)
* Returns the cursor.
*
* @return \MongoCursor The cursor.
- *
- * @api
*/
public function getCursor()
{
@@ -59,6 +53,9 @@ public function getNbResults()
*/
public function getSlice($offset, $length)
{
- return $this->cursor->limit($length)->skip($offset);
+ $this->cursor->limit($length);
+ $this->cursor->skip($offset);
+
+ return $this->cursor;
}
}
@@ -24,8 +24,6 @@ class NullAdapter implements AdapterInterface
* Constructor.
*
* @param integer $nbResults Total item count.
- *
- * @api
*/
public function __construct($nbResults = 0)
{
@@ -47,17 +45,35 @@ public function getNbResults()
* Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
*
* {@inheritdoc}
- *
*/
public function getSlice($offset, $length)
{
- if ($offset >= $this->getNbResults()) {
+ if ($offset >= $this->nbResults) {
return array();
}
- $remainItemCount = $this->getNbResults() - $offset;
- $currentItemCount = $remainItemCount > $length ? $length : $remainItemCount;
+ $nullArrayLength = $this->calculateNullArrayLength($offset, $length);
+
+ return $this->createNullArray($nullArrayLength);
+ }
+
+ private function calculateNullArrayLength($offset, $length)
+ {
+ $remainCount = $this->remainCount($offset);
+ if ($length > $remainCount) {
+ return $remainCount;
+ }
- return array_fill(0, $currentItemCount, null);
+ return $length;
+ }
+
+ private function remainCount($offset)
+ {
+ return $this->nbResults - $offset;
+ }
+
+ private function createNullArray($length)
+ {
+ return array_fill(0, $length, null);
}
}
Oops, something went wrong.

2 comments on commit 103a140

@Koc

This comment has been minimized.

Show comment
Hide comment
@Koc

Koc Mar 31, 2013

What about BC?

Koc replied Mar 31, 2013

What about BC?

@pablodip

This comment has been minimized.

Show comment
Hide comment
@pablodip

pablodip Mar 31, 2013

Contributor

Everything works as before.

Contributor

pablodip replied Mar 31, 2013

Everything works as before.

Please sign in to comment.