我想在身份验证成功后更改默认身份验证过程.我创建了一个在身份验证成功之后和重定向之前调用的服务.
namespace Pkr\BlogUserBundle\Handler;
use Doctrine\ORM\EntityManager;
use Pkr\BlogUserBundle\Service\Encoder\WpTransitionalEncoder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Http\Authentication\Response;
class AuthenticationSuccessHandler implements AuthenticationSuccessHandlerInterface
{
protected $entityManager = null;
protected $logger = null;
protected $encoder = null;
public function __construct(EntityManager $entityManager, LoggerInterface $logger, WpTransitionalEncoder $encoder)
{
$this->entityManager = $entityManager;
$this->logger = $logger;
$this->encoder = $encoder;
}
/**
* This is called when an interactive authentication attempt succeeds. This
* is called by authentication listeners inheriting from
* AbstractAuthenticationListener.
*
* @param Request $request …Run Code Online (Sandbox Code Playgroud) 我最近将我的简历发送给一家雇用PHP开发人员的公司.如果我有足够的经验,他们会给我发回一个要解决的任务.
任务是这样的:
你有一个10k独特元素的数组,排序后代.写入生成此数组的函数,然后编写三个不同的函数,将新元素插入到数组中,插入数组之后仍将按顺序排序.编写一些代码来测量这些功能的速度.您不能使用PHP排序功能.
所以我编写了函数来生成数组和四个函数来将新元素插入到数组中.
/********** Generating array (because use of range() was to simple :)): *************/
function generateSortedArray($start = 300000, $elementsNum = 10000, $dev = 30){
$arr = array();
for($i = 1; $i <= $elementsNum; $i++){
$rand = mt_rand(1, $dev);
$start -= $rand;
$arr[] = $start;
}
return $arr;
}
/********************** Four insert functions: **************************/
// for loop, and array copying
function insert1(&$arr, $elem){
if(empty($arr)){
$arr[] = $elem;
return true;
}
$c = count($arr);
$lastIndex = $c - 1;
$tmp …Run Code Online (Sandbox Code Playgroud) 我现在正在搜索一段时间,以获取有关如何在symfony2中验证成功后执行某些操作的信息.我想在使用旧哈希成功验证后立即重新使用用户密码来使用bcrypt.当我仍然有有效的普通密码时,我需要这样做,所以它应该在凭证检查之后和重定向之前.
任何线索如何实现?
我在Symfony中发现了一些关于事件调度程序的内容,但是在成功验证后我无法找到是否有任何事件.
如果我试图以错误的方式做这个并提出一些更好的方法,请纠正我.
// 编辑
好吧,我发现事件在auth成功之后被触发,它被调用security.authentication.success.所以我现在可以附加到这个事件,但现在我不知道我的边界代码应该在哪里附加我的事件监听器?我应该用我的/src/Pkr/BlogUserBundle/DependencyInjection/PkrBlogUserExtension.phpin load()方法吗?
我正在搜索信息,如果有某种标志/选项强制symfony2验证停止在验证链中的第一个错误.例如,我在我的email领域有三个验证器:
email:
- NotBlank: { groups: [ send_activation_email ] }
- Length: { min: 6, max: 80, charset: UTF-8, groups: [ send_activation_email ] }
- Email: { groups: [ send_activation_email ] }
Run Code Online (Sandbox Code Playgroud)
我想在第一次错误后停止验证.我怎样才能做到这一点?我读了类似的问题:
最后一个是相当不错的,但是当有多个验证器时,是否有任何方法可以在不使用验证组的情况下执行此操作?我在某处看到,在Symfony 2.2中会有一个标志或选项,但我有2.2.1版本,找不到这样的选项.
我正在尝试在会话处理程序和学说 dbal 之间使用与我的数据库相同的连接:
配置文件
framework:
session:
handler_id: session.handler.one_connection_pdo
Run Code Online (Sandbox Code Playgroud)
服务.yml
session.handler.one_connection_pdo:
class: AppBundle\Session\OneConnectionPdoHandler
public: false
arguments:
- "@database_connection"
- []
Run Code Online (Sandbox Code Playgroud)
AppBundle/Session/OneConnectionPdoHandler.php
namespace AppBundle\Session;
use Doctrine\DBAL\Connection;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
class OneConnectionPdoHandler extends PdoSessionHandler
{
public function __construct($pdoOrDsn, array $options)
{
if ($pdoOrDsn instanceof Connection) {
$pdoOrDsn = $pdoOrDsn->getWrappedConnection();
}
parent::__construct($pdoOrDsn, $options);
}
}
Run Code Online (Sandbox Code Playgroud)
浏览应用程序时似乎一切正常,但我无法更新任何实体,因为出现错误:
PDOException: There is already an active transaction
at n/a
in .../vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php line 1176
at PDO->beginTransaction()
in .../vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php line 1176
at Doctrine\DBAL\Connection->beginTransaction()
in .../vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 373
at Doctrine\ORM\UnitOfWork->commit(null)
in .../vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php …Run Code Online (Sandbox Code Playgroud) 我正在使用PhpStorm 2016.2,我的代码完成似乎无法正常工作.打字时$this->assertCo
它建议只有我班级的三级祖先的功能名称.但是,当我使用Ctrl+ Space它建议正确的项目.
这是我的类图:
PHPUnit_Framework_Assert课堂上缺少建议.
如何在不使用Ctrl+的情况下使其工作Space?
PhpStorm和OpenJDK信息:
PhpStorm 2016.2
Build #PS-162.1121.38, built on July 12, 2016
JRE: 1.8.0_76-release-b216 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Run Code Online (Sandbox Code Playgroud) symfony ×3
arrays ×1
autocomplete ×1
autosuggest ×1
connection ×1
doctrine-orm ×1
events ×1
extending ×1
hook ×1
insert ×1
pdo ×1
performance ×1
php ×1
phpstorm ×1
security ×1
session ×1
sorted ×1
symfony-2.2 ×1
validation ×1