PHPackages                             overblog/dataloader-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. overblog/dataloader-bundle

ActiveSymfony-bundle[Caching](/categories/caching)

overblog/dataloader-bundle
==========================

DataLoader Symfony bundle implementation.

v1.1.0(1y ago)472.4M—8.8%12[6 issues](https://github.com/overblog/dataloader-bundle/issues)[1 PRs](https://github.com/overblog/dataloader-bundle/pulls)3MITPHPPHP ^8.1CI passing

Since Feb 4Pushed 8mo ago6 watchersCompare

[ Source](https://github.com/overblog/dataloader-bundle)[ Packagist](https://packagist.org/packages/overblog/dataloader-bundle)[ RSS](/packages/overblog-dataloader-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (16)Used By (3)

DataLoaderBundle
================

[](#dataloaderbundle)

This bundle allows to easy use [DataLoaderPHP](https://github.com/overblog/dataloader-php)in your Symfony project by configuring it through configuration.

[![Build Status](https://camo.githubusercontent.com/7237b057b49b8e30adb03f28810ec97112a88a76204d34f70c615d430fc13fa9/68747470733a2f2f7472617669732d63692e6f72672f6f766572626c6f672f646174616c6f616465722d62756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/overblog/dataloader-bundle)[![Coverage Status](https://camo.githubusercontent.com/6e7d852610031e461b0bccaedee693c91a25a4d39af17ce636159144b619d127/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6f766572626c6f672f646174616c6f616465722d62756e646c652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/overblog/dataloader-bundle?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/fb873afc49df8fe95aeb3c9d72be45db61c28ba6554d0a675b3cb03df135c3aa/68747470733a2f2f706f7365722e707567782e6f72672f6f766572626c6f672f646174616c6f616465722d62756e646c652f76657273696f6e)](https://packagist.org/packages/overblog/dataloader-bundle)[![License](https://camo.githubusercontent.com/5596f6edf802b697e84e45b04711e79b63e3e3a8cdddd173614efdfea8823057/68747470733a2f2f706f7365722e707567782e6f72672f6f766572626c6f672f646174616c6f616465722d62756e646c652f6c6963656e7365)](https://packagist.org/packages/overblog/dataloader-bundle)

Requirements
------------

[](#requirements)

This library requires PHP &gt;= 5.5 to work.

Installation
------------

[](#installation)

### Download the Bundle

[](#download-the-bundle)

```
composer require overblog/dataloader-bundle

```

### Enable the Bundle

[](#enable-the-bundle)

```
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...

            new Overblog\DataLoaderBundle\OverblogDataLoaderBundle(),
        ];

        // ...
    }

    // ...
}
```

Getting Started
---------------

[](#getting-started)

Here a fast example of how you can use the bundle

```
overblog_dataloader:
    defaults:
        # required
        promise_adapter: "overblog_dataloader.react_promise_adapter"
        # optional
        factory: ~
        options:
            batch: true
            cache: true
            max_batch_size: ~
            cache_map: "overblog_dataloader.cache_map"
            cache_key_fn: ~
    loaders:
        users:
            alias: "users_dataloader"
            batch_load_fn: "@app.user:getUsers"
        posts:
            batch_load_fn: "Post::getPosts"
            options:
                max_batch_size: 15
                batch: false
                cache: false
                cache_map: "app.cache.map"
                cache_key_fn: "@app.cache"
        images:
            factory: my_factory
            batch_load_fn: "Image\\Loader::get"
```

This example will create 3 loaders as services:

- "@overblog\_dataloader.users\_loader" with alias "@users\_dataloader"
- "@overblog\_dataloader.posts\_loader"
- "@overblog\_dataloader.images\_loader" create using custom factory function "my\_factory"

Here the list of existing promise adapters:

- **[ReactPhp/Promise](https://github.com/reactphp/promise)**: overblog\_dataloader.react\_promise\_adapter
- **[GuzzleHttp/Promises](https://github.com/guzzle/promises)**: overblog\_dataloader.guzzle\_http\_promise\_adapter
- **[Webonyx/GraphQL-PHP](https://github.com/webonyx/graphql-php) Sync Promise**: overblog\_dataloader.webonyx\_graphql\_sync\_promise\_adapter

Configuration using attributes
------------------------------

[](#configuration-using-attributes)

This bundle supports autoconfiguration via attributes. Add `Overblog\DataLoaderBundle\Attribute\AsDataLoader` on the service you want to expose as data loader:

```

```

Combine with GraphQLBundle
--------------------------

[](#combine-with-graphqlbundle)

This bundle can be use with [GraphQLBundle](https://github.com/overblog/GraphQLBundle). Here an example:

- Bundle config

```
#graphql
overblog_graphql:
    definitions:
        schema:
            query: Query
    services:
        promise_adapter: "webonyx_graphql.sync_promise_adapter"

#dataloader
overblog_dataloader:
    defaults:
        promise_adapter: "overblog_dataloader.webonyx_graphql_sync_promise_adapter"
    loaders:
        ships:
            alias: "ships_loader"
            batch_load_fn: "@app.graph.ships_loader:all"
```

- Batch loader function

```
services:
    app.graph.ship_repository:
        class: AppBundle\Entity\Repository\ShipRepository
        factory: ["@doctrine.orm.entity_manager", getRepository]
        arguments:
            - AppBundle\Entity\Ship

    app.graph.ships_loader:
        class: AppBundle\GraphQL\Loader\ShipLoader
        arguments:
            - "@overblog_graphql.promise_adapter"
            - "@app.graph.ship_repository"
```

```
