From 1334236bb6059b2302a760196ce7885df379e984 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 6 Mar 2022 11:45:31 +0100 Subject: toml to yaml --- src/Controllers/EntriesController.php | 4 ++-- src/Controllers/SubmissionController.php | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src/Controllers') diff --git a/src/Controllers/EntriesController.php b/src/Controllers/EntriesController.php index 801fe7b..f45866a 100644 --- a/src/Controllers/EntriesController.php +++ b/src/Controllers/EntriesController.php @@ -2,7 +2,7 @@ namespace FlatFileForms\Controllers; -use Yosymfony\Toml\Toml; +use Symfony\Component\Yaml\Yaml; class EntriesController { @@ -65,7 +65,7 @@ class EntriesController $entriesForDay = $utilities->scandir($dayPath); foreach ($entriesForDay as $entryForDay) { - $entry = Toml::parseFile($entryForDay); + $entry = Yaml::parseFile($entryForDay); if (isset($_GET['flat'])) { $entries[] = $entry; } else { diff --git a/src/Controllers/SubmissionController.php b/src/Controllers/SubmissionController.php index 2c3d603..8d7d9e6 100644 --- a/src/Controllers/SubmissionController.php +++ b/src/Controllers/SubmissionController.php @@ -3,13 +3,21 @@ namespace FlatFileForms\Controllers; use FlatFileForms\Builder; +use FlatFileForms\Form; +use FlatFileForms\HookManager; use FlatFileForms\Validator; -use Yosymfony\Toml\TomlBuilder; +use Symfony\Component\Yaml\Yaml; class SubmissionController { public function submit(Builder $builder, Validator $validator, string $formPath): array { + /**@var HookManager $hooks*/ + global $hooks; + + /**@var Form $form*/ + global $form; + $fields = $builder->buildFields(); // run through validation @@ -21,23 +29,19 @@ class SubmissionController if (empty($result['error'])) { $date = new \Datetime(); $entry = [ - 'fields' => $_POST, 'date' => $date->format('c'), + 'fields' => $_POST, ]; - $entryBuilder = new TomlBuilder(); - $entryBuilder->addValue('date', $entry['date']); - $entryBuilder->addTable('fields'); - foreach ($entry['fields'] as $entryKey => $entryValue) { - $entryBuilder->addValue($entryKey, $entryValue); - } + $entry = $hooks->applyFilter("submit:{$form->name}:entry", $entry); + $entry = $hooks->applyFilter('submit:entry', $entry); $entryDirectory = $formPath . '/entries/' . $date->format('Y/m/d'); @mkdir($entryDirectory, 0774, true); - $entryFilename = $date->format('Ymd_Hi_') . hash('adler32', serialize($entry)) . '.toml'; + $entryFilename = $date->format('Ymd_Hi_') . hash('adler32', serialize($entry)) . '.yaml'; file_put_contents( $entryDirectory . '/' . $entryFilename, - $entryBuilder->getTomlString() + Yaml::dump($entry, 4) ); } else { -- cgit v1.2.3