...A Design Pattern

Converter & Populator

Intent

In some situations we have to transform Pimcore Objects into a different world.

 

Typical example are View objects or Elastic search engine objects.

Bayer 04

DSV

Multi-Type Conversion

Jerseys

Vouchers

Soccer School

Other
Merchandising
Articles

Different Product Types

Different Product Views

ProductView

VoucherView

JerseyView

SoccerSchoolView

Single-Type
Conversion

In our DSV Project we had:

  • 9 nations (each one site)
  • 8 cultures
    (Getreide, Mais, Raps,...)
  • with several sub-cultures
  • and different varieties
     
  • Each variety had over 50 attributes
     
  • About 150 BSA-Criteria,
    • containing digit values (0-9)
    • represented by different texts

Pimcore
Model

  • 7 different Product Classes
     
  • over 50 attributes per Class
     
  • Advanced-Many-to-Many-Relations with over 150 other objects

Different Views

Single-Type
Conversion

class SorteView extends BaseSorteView
{
    ...
    
    /**
     * @var TableView[]
     */
    private array $tables = [];

    /**
     * @var LongTextView[]
     */
    private array $longTexts = [];

    ... // Getters & Setters
}

Dynamic Structure

MultiType Conversion

SingleType Conversion

Dynamic Structure

Motivation

Separating different concerns of representing objects

Being uncoupled from external systems (ERP, Printing, ...)

Separating transformation logic from templates itself

Making transformation much more testable

Keeping high cohesion of transforming attribute-wise by
Populators

Applicability

"Use this pattern wherever you have to map a typed object from one universe to another"

Entities
Pimcore
DataObjects

Symfony Services

Symfony Controllers

Product

ERPProduct

ProductDTO

ProductView

ProductPrintDTO

ProductEntity

ProductBonus

Consequences

Each Populator can be implemented quite simple and test-driven.

For setting specific attribute values one can use the whole power of PHP programming
(e.g. instead of Twig functions)

Transformation becomes Backend development task

Supports Open-Closed-Principle

Design by Contract

Code Generation Bundle

Extensions and Future

Generalization of TableView- and TableRow Population from DSV

Generic (polymorphic) approach

http://www.michael-albrecht.de
 

@Michael_HB
 

 m.albrecht@neusta.de
 

Development Amplifier
Java CAT & PHP Pussy

Michael Albrecht - team neusta