public function testGettersAndSetters() { $this->assertNull($this->subscriber->getId()); $this->assertNull($this->subscriber->getEmail()); $this->assertNull($this->subscriber->getUnsubscribeToken()); $this->subscriber->setEmail('*****@*****.**'); $this->subscriber->setUnsubscribeToken('some-token'); $this->assertSame('*****@*****.**', $this->subscriber->getEmail()); $this->assertSame('some-token', $this->subscriber->getUnsubscribeToken()); }
} })]])->add('subscribe', 'submit', ['attr' => ['class' => 'btn-default']])->getForm(); $app['slack-subscribe-form'] = $app['form.factory']->createBuilder('form')->add('email', 'text', ['attr' => ['placeholder' => 'Your email'], 'constraints' => new Assert\Email()])->add('token', 'text', ['attr' => ['placeholder' => 'Your slack token'], 'constraints' => new Assert\NotBlank()])->add('channel', 'text', ['attr' => ['placeholder' => 'The slack channel to post to'], 'constraints' => new Assert\NotBlank()])->getForm(); $app->register(new DoctrineServiceProvider(), array("db.options" => array('driver' => 'pdo_sqlite', 'path' => __DIR__ . '/../data/app.db'))); $app->register(new DoctrineOrmServiceProvider(), ["orm.proxies_dir" => "/path/to/proxies", "orm.em.options" => ["mappings" => [["type" => "annotation", "namespace" => 'MikeyMike\\RfcDigestor\\Entity', "path" => __DIR__ . "/../src/Entity"]]]]); $app->get('/', function () use($app) { $form = $app['subscribe-form']; $slackForm = $app['slack-subscribe-form']; return $app['twig']->render('index.twig', ['form' => $form->createView(), 'slack_form' => $slackForm->createView()]); }); $app->post('/email-subscribe', function (Request $request) use($app) { $form = $app['subscribe-form']; $form->handleRequest($request); if ($form->isValid()) { $email = $form->getData()['email']; $subscriber = new Subscriber(); $subscriber->setEmail($email); $subscriber->setUnsubscribeToken(bin2hex(openssl_random_pseudo_bytes(16))); $em = $app['orm.em']; $em->persist($subscriber); $em->flush(); $app['session']->getFlashBag()->add('message', sprintf('You successfully subscribed with %s', $email)); return $app->redirect('/'); } return $app['twig']->render('index.twig', ['form' => $form->createView(), 'slack_form' => $app['slack-subscribe-form']->createView()]); }); $app->post('/slack-subscribe', function (Request $request) use($app) { $slackForm = $app['slack-subscribe-form']; $slackForm->handleRequest($request); if ($slackForm->isValid()) { $email = $slackForm->getData()['email'];