Skip to content

Profile definition

Alexey Pavlyuts edited this page Jan 22, 2023 · 1 revision

Profile data structure defines how data handled on:

  1. Creation Entyty class instances from CSV records
  2. Export Entity class instancess to CSV

The profile allows to define CSV object representation without coding and performs the most routine tasks.

Typical profile data structure content for typical invoice

$invoiceProfile = [
    'strict' => true,
    'fields' => [
        "Customer ID" => [
            'type' => 'text',
            'scope' => 'shared',
        ],
        "Invoice #" => [
            'type' => 'id',
            'scope' => 'shared',
        ],
        "Date" =>[
            'type' => 'date',
            'format' => 'm/d/y',
            'scope' => 'shared',
        ],
        "Date Due" =>[
            'type' => 'date',
            'format' => 'm/d/y',
            'scope' => 'shared',
        ],
        "Rows count" =>[
            'type' => 'rowCount',
            'scope' => 'shared',
        ],
        "Row #" =>[
            'type' => 'rowIndex',
            'scope' => 'row',
        ],
        "Goods Description" =>[
            'type' => 'text',
            'scope' => 'row',
        ],
        "Price" =>[
            'type' => 'number',
            'import' => ['invert'],
            'export' => ['invert'],
            'scope' => 'row',
        ],
        "Quantity" =>[
            'type' => 'number',
            'scope' => 'row',
        ],
        "Total" =>[
            'type' => 'number',
            'import' => ['invert'],
            'export' => ['invert'],
            'scope' => 'row',
        ],
    ],
];

For the object we define:

And then the array, defining each field profile, it's type and processing options. Array key means CSV file column name, if header notgiven it will be allocated in the order of fields list.

scope option controls field meaning:

  • shared if the CSV column contains repeating object-level value like Customer ID
  • 'row' or absent - the data vary from row to row and handled as object row element

type defines how to handle the value in export and import

Type Meaning Import from CSV Export to CSV Remark
id Main object identifier like invoice # As is As is Only one per fields list allowed
text Text field As is As is
date Date or datetime Converted to php DateTime class instance Converted from DateTime to sttring format option used to control str<>DateTime
rowCount The count of object rows Checked, throw Exception if rowcount field does not match the coount of row given Filled with dataset row count optional, only one per fields list allowed
rowIndex Row # in the object As is If not given in the dataset but configured - lines be numbered starting from 1 optional, only one per fields list allowed
number As is As is
Clone this wiki locally