graze / dal

Data Access Layer
MIT License
8 stars 0 forks source link

Support for custom collection classes #6

Closed wpillar closed 10 years ago

wpillar commented 10 years ago

This means that configuration for an entity relationship can define a custom collection class:

$config = [
    'Graze\Lib\Entity\Account' => [
        'record' => 'Account',
        'related' => [
            'brand' => ['entity'=>'Graze\Lib\Entity\Brand', 'method'=>'getBrand'],
            'statuses' => [
                'entity' => 'Graze\Lib\Entity\Account\Status',
                'method' => 'getActiveStatuses',
                'collection' => 'Graze\Lib\Account\Status\StatusCollection'
            ]
        ]
    ],
    'Graze\Lib\Entity\Account' => [
        'record' => 'Account',
        'related' => [
            'brand' => ['entity'=>'Graze\Lib\Entity\Brand', 'method'=>'getBrand'],
            'statuses' => [
                'entity' => 'Graze\Lib\Entity\Account\Status',
                'method' => 'getActiveStatuses',
                'collection' => true
            ]
        ]
    ]
];

The collection attribute can either be a string with the class name for the custom collection or boolean to default to the Doctrine\Common\Collections\ArrayCollection.

adlawson commented 10 years ago

Looks pretty solid to me, so I'm happy. It lacks tests, but so does the rest of the library at the minute so I'm not too fussed.

I'll add it to my list of things.

wpillar commented 10 years ago

Ta. Yeh wasn't sure what the deal was with tests. Looked like it would be quite a complex mocking tree/graph/chain for the proxy stuff.

adlawson commented 10 years ago

Do you think we should check the type of the new collection? i.e check it extends Doctrine\Common\Collections\ArrayCollection?

Not a big deal just now, but I might add an issue to that effect.

wpillar commented 10 years ago

I wondered about that. Is there anywhere DAL depends on it being ArrayCollection? I guess it depends on being able to inject an array of stuff into the constructor, so maybe it should check the type of it.