/** * @param Application $application */ private function exampleOfFormHandling(Application $application) { $application->post('contact', function (Request $request, StaticController $staticController) { if (!$request->get('email')) { //if the form is not filled, we display the form with the error return $staticController->render(['text-danger' => 'Form not filled']); } //send the email... //if the email is send, we redirect to avoid F5. return $staticController->redirect(['text-info' => sprintf('Email sent from %s', $request->get('email'))]); }); }
public function testPostWithAdditionalFilter() { $controller = function () { }; $application = new Application(new \ArrayObject(), new Request()); $application->post('pattern', $controller)->method('method')->content('content'); /** * @var Router $router */ $router = $application->getServices()['router']; $route = $router->getRoutes()[0]; $this->assertSame('pattern', $route->getPattern()->getUri()); $this->assertSame('METHOD', $route->getPattern()->getMethod()); $this->assertSame('content', $route->getPattern()->getContentType()); }