/** * @param Resources $mvc */ public function formAction(Resources $mvc) { $flags = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT; $request = $mvc('request'); $escape = $mvc->helper('escape'); // $file = DATA_ROOT . "/form.json"; $form = new Util\Form($escape); $form->load(APPLICATION_ROOT . "/form/contact.yaml"); $data = file_exists($file) ? json_decode(file_get_contents($file), true) : []; $form->hydrate($data); if ($request->isMethod('POST')) { $form->input($mvc->input('POST')); // $form->input(INPUT_POST); $data = json_encode($form->extract(), $flags); $temp = "{$file}.part"; file_put_contents($temp, $data); rename($temp, $file); } return ['form' => $form, 'elapsed' => $this->elapsedTime()]; }