Hydrator for array of File elements

zend-mvc

#1

A User has a DocumentBox that contains Documents - entities that point to a file on disk that’s been uploaded.

Uploads happen via the Zend\Form\Element\File. Multi-file upload is enabled.

I have it all working, but I don’t think I’m doing it right.

I understand incoming files come in via $_FILES. I also know to do this in my controller action:

    $data = array_merge_recursive(
        $request->getPost()->toArray(),
        $request->getFiles()->toArray()
    );

But I use a controller plugin to pull new files from the Form’s InputFilter (so they’re all renamed, etc.) and call my domain model to actually attach them to the User.

This feels like “doing it wrong”, but I can’t see how to use a Hydrator or HydratorStrategy when, when editing the DocumentBox with a form, the new files in the DocumentBox and the existing files are not represented in the Form in the same way. The existing files are shown as a checklist (to enable deleting), and the new files come in via $_FILES.

It seems like a particularly weird case that can only be handled by manually hydrating/extracting to/from different Form elements.