Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Generated hydrator and extractor should be a closure, not a class #64

@Ocramius

Description

@Ocramius

As per discussions in #59, hydrator and extractor shouldn't be composed into a zend-hydrator, but should instead be two closures.

An example API would be:

interface GenerateHydrator 
{
    public function __invoke(string $className) : callable;
}

interface GenerateExtractor 
{
    public function __invoke(string $className) : callable;
}

They would be used as following:

$object = $generateHydrator->__invoke(get_class($object))($object, $data); 
$data = $generateExtractor->__invoke(get_class($object))($object); 

Composing them into a Hydrator instance that follows zend-hydrator spec is simple, but we'd also get a decent performance improvement by just relying on functional composition above.

This would allow us to:

  • gain performance (one less method call per hydrate/extract)
  • remove the need of the visitor pattern to modify an existing class (we just generate closures from scratch)
  • simplify API
  • provide type-safe closures (since we can add parameter and return type hints)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions