Skip to content
Browse files

updated documentation related to join of events, closes #70

  • Loading branch information...
1 parent ef12b1d commit d0228d14e7bf4695c790c2b25758849ff1281130 @l3pp4rd l3pp4rd committed
Showing with 11 additions and 17 deletions.
  1. +5 −0 README.md
  2. +6 −17 Resources/doc/custom_pagination_subscribers.md
View
5 README.md
@@ -9,6 +9,11 @@ older version of KnpPaginatorBundle - use **v1.0** tag in the repository
## Latest updates
+**2011-12-16**
+
+- Joined **count** and **items** events into one **items** which now populates
+count and item result on event. This way it is more straightforward and cleaner
+
**2011-12-09**
- Changed event names to more distinctive. Using main symfony event dispatcher service.
View
23 Resources/doc/custom_pagination_subscribers.md
@@ -24,14 +24,11 @@ namespace Acme\DemoBundle\Subscriber;
use Symfony\Component\Finder\Finder;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-use Knp\Component\Pager\Event\CountEvent;
use Knp\Component\Pager\Event\ItemsEvent;
class PaginateDirectorySubscriber implements EventSubscriberInterface
{
- private $files;
-
- public function count(CountEvent $event)
+ public function items(ItemsEvent $event)
{
if (is_string($event->target) && is_dir($event->target)) {
$finder = new Finder;
@@ -41,17 +38,10 @@ class PaginateDirectorySubscriber implements EventSubscriberInterface
->in($event->target)
;
$iter = $finder->getIterator();
- $this->files = iterator_to_array($iter);
- $event->count = count($this->files);
- $event->stopPropagation();
- }
- }
-
- public function items(ItemsEvent $event)
- {
- if (is_string($event->target) && is_dir($event->target)) {
+ $files = iterator_to_array($iter);
+ $event->count = count($files);
$event->items = array_slice(
- $this->files,
+ $files,
$event->getOffset(),
$event->getLimit()
);
@@ -62,14 +52,13 @@ class PaginateDirectorySubscriber implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return array(
- 'knp_pager.items' => array('items', 1/*increased priority to override any internal*/),
- 'knp_pager.count' => array('count', 1/*increased priority*/)
+ 'knp_pager.items' => array('items', 1/*increased priority to override any internal*/)
);
}
}
```
-Class above is the simple event subscriber, which listens to **knp_pager.count** and **knp_pager.items** events.
+Class above is the simple event subscriber, which listens to **knp_pager.items** event.
Creates a finder and looks in this directory for files. To be more specific it will look
for the **files** in the directory being paginated, max in 3 level depth.

0 comments on commit d0228d1

Please sign in to comment.
Something went wrong with that request. Please try again.