PHPackages                             zenbox/doctrine - 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. [Database &amp; ORM](/categories/database)
4. /
5. zenbox/doctrine

ActiveLibrary[Database &amp; ORM](/categories/database)

zenbox/doctrine
===============

Doctrine extensions

2.1.5(4y ago)11.9k↓50%1MITPHPPHP ^8.1

Since Jan 26Pushed 4y ago2 watchersCompare

[ Source](https://github.com/zenbox-group/doctrine)[ Packagist](https://packagist.org/packages/zenbox/doctrine)[ Docs](https://github.com/zenbox-group/doctrine)[ RSS](/packages/zenbox-doctrine/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (11)Used By (1)

ZenBox Doctrine
===============

[](#zenbox-doctrine)

[![PHP Version](https://camo.githubusercontent.com/98759f7aaf1237ed050cbccc4b7ce9b64775ad3bdaa40b1f98f357299a31ad3b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7a656e626f782f646f637472696e652e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/zenbox/doctrine)[![Stable Version](https://camo.githubusercontent.com/3a2f16a68117fcf5e15079b59ae388b7430da0b108af6dfb6507ca349866f1a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a656e626f782f646f637472696e652e7376673f7374796c653d666f722d7468652d6261646765266c6162656c3d4c6174657374)](https://packagist.org/packages/zenbox/doctrine)[![Total Downloads](https://camo.githubusercontent.com/4c773823a35354d870487995fc967945bb88543b8bd67374321c9304e2eb2181/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a656e626f782f646f637472696e652e7376673f7374796c653d666f722d7468652d6261646765266c6162656c3d546f74616c2b646f776e6c6f616473)](https://packagist.org/packages/zenbox/doctrine)

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

[](#installation)

Using Composer:

```
composer require zenbox/doctrine
```

What is contained in the package?
---------------------------------

[](#what-is-contained-in-the-package)

### Doctrine components

[](#doctrine-components)

- [ORM](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/index.html)
- [Migrations](https://www.doctrine-project.org/projects/doctrine-migrations/en/3.0/index.html)
- [Fixtures](https://github.com/doctrine/data-fixtures)

### QueryBuilderCollection

[](#querybuildercollection)

Lazy load query builder collection

```
$qb = $this->createQueryBuilder('a');
$qb->orderBy('a.date','DESC');
$collection = new QueryBuilderCollection($qb);

$collection->count(); // returns the total number of records
$collection->slice(0, 10); // request limited 10 records from the database
```

### DataProvider

[](#dataprovider)

Can be used for pagination. 20 records per page by default

```
use Doctrine\Common\Collections\ArrayCollection;

$dataProvider = new DataProvider(new ArrayCollection([...]));

// iterable
foreach ($dataProvider as $object) {
    // do something
}

$array = $dataProvider->toArray(); // returns 20 records
```

Extract data from objects

```
use ZenBox\Doctrine\Extractor\ExtractorInterface;

// implement extractor
class UserExtractor implements ExtractorInterface
{
    public function extract(object $object) : array
    {
        // TODO: Implement extract() method.
    }
}
// fetch collection from repository
$collection = $repository->findAll();
$dataProvider = new DataProvider($collection, new UserExtractor());

// iterable
foreach ($dataProvider as $row) {
    // do something
}

$array = $dataProvider->extract(); // returns 20 rows
```

### Console commands

[](#console-commands)

You need to create a file `./bin/doctrine` in your project for use console commands

```
#!/usr/bin/env php
