# Creating custom subscriber
Lets say we want to paginate a directory content, might be quite interesting.
And when we have such a handy **Finder** component in symfony, its easily achievable.
## Prepare environment
I will assume we you just installed [symfony-standard](https://github.com/symfony/symfony-standard)
edition and you install [KnpPaginatorBundle](https://github.com/knplabs/KnpPaginatorBundle).
Follow the installation guide on these repositories, its very easy to setup.
## Create subscriber
Next, lets extend our **AcmeDemoBundle** which comes together with **symfony-standard** edition.
Create file **../symfony-standard/src/Acme/DemoBundle/Subscriber/PaginateDirectorySubscriber.php**
``` php
target) && is_dir($event->target)) {
$finder = new Finder;
$finder
->files()
->depth('< 4') // 3 levels
->in($event->target)
;
$iter = $finder->getIterator();
$files = iterator_to_array($iter);
$event->count = count($files);
$event->items = array_slice(
$files,
$event->getOffset(),
$event->getLimit()
);
$event->stopPropagation();
}
}
public static function getSubscribedEvents()
{
return array(
'knp_pager.items' => array('items', 1/*increased priority to override any internal*/)
);
}
}
```
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.
## Register subscriber as service
Next we need to tell **knp_paginator** about our new fancy subscriber which we intend
to use in pagination. It is also very simple, create additional service config file:
**../symfony-standard/src/Acme/DemoBundle/Resources/config/paginate.xml**
``` html
base name | path |
---|---|
{{ file.getBaseName() }} | {{ file.getPath() }} |