Designing a system to import CSV files and running rules on them

Hi all

I’ve got an application design question. I want to import various CSV files into a database but rules need to be run on the records to decide which ones should be imported. For the rules I’m intending using this:

I’d like to know thoughts and opinions on my approach to this.

This is how I’m thinking roughly this should work:

1 - set up the route to accommodate different csv files:

$app->get('/{suppplier:[a-zA-Z}/', \App\Action\CsvImportAction::class . ':import');

2 - create the class CsvImportAction with an import method

3 - Inject the Ruler dependencies (these would be factory classes) into the CsvImportAction constructor

4 - Define the import method. Pass in the value from the route and use the value to load the appropriate class calling a getRules() method to get those specific rules (different classes would have different rules, these rules would eventually be more likely stored in the DB too). This might look something like this:

public function getRules()
     return $rules = array(
                  'has_quantity' = > true,
                  'has_quantity_column_position' => 0,
                  'has_date' => true,
                  'has_date_column_position' => 1,
                  'date_within_7_days' = > true,
                  'date_within_7_days_column_position' = > 2,
                  'discontinued' => false,
                  'discontinued_column_position' => 3,

5 - load the CSV file

6 - In the import method create the various RuleBuilder etc objects using the Ruler package.

7 - Iterate over the CSV and apply the rules to each line

8 - Update the DB after the rules have been applied

Thank you in advance!