phpro / zf-doctrine-hydration-module

Configurable Doctrine hydrators for ZF2
18 stars 33 forks source link

Ability to Configure Hydrator Filters #8

Closed gsomoza closed 9 years ago

gsomoza commented 9 years ago

Adds the ability to configure filters for the hydrator:

    // ...
    'doctrine-hydrator' => array(
        'Acme\\V1\\Rest\\User\\UserHydrator' => array (
            // ...
            'filters' => array(
                // a service...
                'Acme\\V1\\Rest\\Person\\PersonFilter',
                // .. or a lambda / anonymous function ...
                'optional_key' => function($field) {
                    return true; // will always exclude the field
                },
                // ... or an array
                array(
                    'filter'    => 'service' // or lambda,
                    'condition' => FilterComposite::CONDITION_AND, // default is OR
                ),
            ),
        ),
    ),

If this is interesting then I can throw a few more things in - e.g. a very easy way to exclude fields (by providing some built-in filters).

veewee commented 9 years ago

Thanks for contributing! Before I can merge this pull request, can you please make following adjustments:

Maybe it is better to only allow one type of configuration. This makes this component easier to understand / use.

Maybe something like:

<?php
'doctrine-hydrator' => [
    'customhydrator' => [
        // .... other config
        'filters' => [
            'custom-filter-name' => [
                'condition' => 'and',
                'filter' => 'Filter\Key\In\ServiceManager'
            ],
        ],
    ],
],

So:

When this feature is good to go, it is possible to create some build-in features if they are related to specific doctrine problems.

gsomoza commented 9 years ago

Sure, they're very reasonable changes - I'll have them ready soon.

gsomoza commented 9 years ago

Looks like the build was failing due to the php-cs-fixer. Would you like me to make a commit that includes all the changes from the fixer, even if they're not related to my changes?

veewee commented 9 years ago

I already fixed the cs errors on master and merged your commit. Thanks!

gsomoza commented 9 years ago

I forgot to add the details in the README. Will do that soon.

veewee commented 9 years ago

The configuration details are added to the README. Feel free to add extra information.

gsomoza commented 9 years ago

Added a bit more info.