当前位置: 首页>>代码示例>>PHP>>正文


PHP Container::namedForm方法代码示例

本文整理汇总了PHP中Pimple\Container::namedForm方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::namedForm方法的具体用法?PHP Container::namedForm怎么用?PHP Container::namedForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pimple\Container的用法示例。


在下文中一共展示了Container::namedForm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register


//.........这里部分代码省略.........
         }
         if ($token->getConsumed()) {
             throw new TokenException("Token already used", TokenException::ALREADY_USED);
         }
         switch ($token->getType()) {
             case 'email_verification':
                 $token->getUser()->setEmailVerified(true);
                 $token->setConsumed(true);
                 $token->setConsumedAt(new \DateTime());
                 $app['orm.em']->flush();
                 return true;
             case 'require_email_verification':
                 $token->getUser()->setEmailVerified(true);
                 $token->getUser()->setEnabled(true);
                 $token->setConsumed(true);
                 $token->setConsumedAt(new \DateTime());
                 $app['orm.em']->flush();
                 return true;
             case 'recover_password':
                 if ($data) {
                     // submit
                     $token->setConsumed(true);
                     $token->setConsumedAt(new \DateTime());
                 }
                 $token->getUser()->setEmailVerified(true);
                 $app['orm.em']->flush();
                 return true;
         }
     });
     // build the user_register form
     $app[$dns . 'register_form_builder'] = $app->protect(function ($request) use($app, $dns) {
         $data = $request->getSession()->get($dns . 'register_form', []);
         $name = $request->get('_firewall');
         $builder = $app->namedForm('user_register', $data);
         if (!$app[$dns . 'firewalls'][$name]['use_email_as_username']) {
             $builder->add('username', TextType::class, ['label' => $dns . 'register.labels.username']);
         }
         /** @var \Symfony\Component\Form\FormBuilder $builder */
         $builder->add('email', EmailType::class, ['label' => $dns . 'register.labels.email'])->add('password', PasswordType::class, ['always_empty' => !$app[$dns . 'firewalls'][$name]['render_password_value'], 'label' => $dns . 'register.labels.password', 'attr' => ['autocomplete' => 'off']])->add('confirm_password', PasswordType::class, ['always_empty' => !$app[$dns . 'firewalls'][$name]['render_password_value'], 'label' => $dns . 'register.labels.confirm_password', 'attr' => ['autocomplete' => 'off']])->add('submit', SubmitType::class, ['label' => $dns . 'register.labels.submit']);
         if ($request->get('_login_route')) {
             $builder->add('cancel', SubmitType::class, ['label' => $dns . 'register.labels.cancel']);
         }
         return $builder;
     });
     // build the validators constraints for the registration user data
     $app[$dns . 'register_constraints_builder'] = $app->protect(function ($request, $data) use($app, $dns) {
         $name = $request->get('_firewall');
         $constraints = [];
         $constraints['email'] = new Constraints\Email();
         if (!$app[$dns . 'firewalls'][$name]['use_email_as_username']) {
             $constraints['username'] = [new Constraints\Length(['min' => 8, 'minMessage' => $dns . 'register.validators.username.length.min', 'max' => 16, 'maxMessage' => $dns . 'register.validators.username.length.max']), new Constraints\Regex(['pattern' => '/^[a-z][a-z0-9]*$/i', 'message' => $dns . 'register.validators.username.regex.username'])];
         }
         $constraints['password'] = new Constraints\Length(['min' => 8, 'minMessage' => $dns . 'register.validators.password.length.min', 'max' => 16, 'maxMessage' => $dns . 'register.validators.password.length.max']);
         $constraints['confirm_password'] = new Constraints\EqualTo(['value' => $data['password'], 'message' => $dns . 'register.validators.confirm_password.equal_to.password']);
         return $constraints;
     });
     $app[$dns . 'password_recoverer'] = $app->protect(function ($request, $email) use($app, $dns) {
         $app[$dns . 'init_options']();
         $name = $request->get('_firewall');
         /** @var \Quazardous\Silex\UserPack\Entity\UserInterface $dbUser */
         $dbUser = $app['orm.em']->getRepository($app[$dns . 'user_entity_class'])->findOneBy([$app[$dns . 'user_entity_email_field'] => $email]);
         if ($dbUser) {
             $dbToken = $app[$dns . 'secure_token_factory']($dbUser, 'recover_password');
             $app['orm.em']->flush();
             $data = ['user' => $dbUser, 'token' => $dbToken->getToken(), 'login_route' => $request->get('_login_route'), 'register_route' => $request->get('_register_route'), 'recover_password_confirm_route' => $request->get('_recover_password_confirm_route'), 'from' => $app[$dns . 'firewalls'][$name]['mailer_from']];
             $app[$dns . 'mailer']('recover_password', $data);
开发者ID:quazardous,项目名称:silex-user-pack,代码行数:67,代码来源:SilexUserPack.php


注:本文中的Pimple\Container::namedForm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。