Fixed some issues with symfony firewall and ModelType.
This commit is contained in:
parent
3ac67e95e5
commit
8f2ac4c3fa
51
DependencyInjection/Security/UserProvider/PropelFactory.php
Normal file
51
DependencyInjection/Security/UserProvider/PropelFactory.php
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
namespace Propel\PropelBundle\DependencyInjection\Security\UserProvider;
|
||||||
|
|
||||||
|
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
|
||||||
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
||||||
|
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
/**
|
||||||
|
* PropelFactory creates services for Propel user provider.
|
||||||
|
*
|
||||||
|
* @author William Durand <william.durand1@gmail.com>
|
||||||
|
*/
|
||||||
|
class PropelFactory implements UserProviderFactoryInterface
|
||||||
|
{
|
||||||
|
private $key;
|
||||||
|
private $providerId;
|
||||||
|
public function __construct($key, $providerId)
|
||||||
|
{
|
||||||
|
$this->key = $key;
|
||||||
|
$this->providerId = $providerId;
|
||||||
|
}
|
||||||
|
public function create(ContainerBuilder $container, $id, $config)
|
||||||
|
{
|
||||||
|
$container
|
||||||
|
->setDefinition($id, new DefinitionDecorator($this->providerId))
|
||||||
|
->addArgument($config['class'])
|
||||||
|
->addArgument($config['property'])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
public function getKey()
|
||||||
|
{
|
||||||
|
return $this->key;
|
||||||
|
}
|
||||||
|
public function addConfiguration(NodeDefinition $node)
|
||||||
|
{
|
||||||
|
$node
|
||||||
|
->children()
|
||||||
|
->scalarNode('class')->isRequired()->cannotBeEmpty()->end()
|
||||||
|
->scalarNode('property')->defaultNull()->end()
|
||||||
|
->end()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
|
@ -204,11 +204,10 @@ class ModelChoiceList extends ObjectChoiceList
|
||||||
$filterBy = 'filterBy' . current($this->identifier)->getPhpName();
|
$filterBy = 'filterBy' . current($this->identifier)->getPhpName();
|
||||||
// The initial query is cloned, so all additional filters are applied correctly.
|
// The initial query is cloned, so all additional filters are applied correctly.
|
||||||
$query = clone $this->query;
|
$query = clone $this->query;
|
||||||
$result = (array)$query
|
$query
|
||||||
->$filterBy(
|
->$filterBy($values)
|
||||||
$values
|
;
|
||||||
)
|
$result = iterator_to_array($query->find());
|
||||||
->find();
|
|
||||||
// Preserve the keys as provided by the values.
|
// Preserve the keys as provided by the values.
|
||||||
$models = array();
|
$models = array();
|
||||||
foreach ($values as $index => $value) {
|
foreach ($values as $index => $value) {
|
||||||
|
@ -424,10 +423,10 @@ class ModelChoiceList extends ObjectChoiceList
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$models = (array)$this->query->find();
|
$models = iterator_to_array($this->query->find());
|
||||||
$preferred = array();
|
$preferred = array();
|
||||||
if ($this->preferredQuery instanceof ModelCriteria) {
|
if ($this->preferredQuery instanceof ModelCriteria) {
|
||||||
$preferred = (array)$this->preferredQuery->find();
|
$preferred = iterator_to_array($this->preferredQuery->find());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
namespace Propel\PropelBundle;
|
namespace Propel\PropelBundle;
|
||||||
|
|
||||||
|
use Propel\PropelBundle\DependencyInjection\Security\UserProvider\PropelFactory;
|
||||||
use Propel\Runtime\Propel;
|
use Propel\Runtime\Propel;
|
||||||
use Propel\Runtime\Connection\ConnectionManagerSingle;
|
use Propel\Runtime\Connection\ConnectionManagerSingle;
|
||||||
use Propel\Runtime\Connection\ConnectionManagerMasterSlave;
|
use Propel\Runtime\Connection\ConnectionManagerMasterSlave;
|
||||||
|
@ -35,7 +36,8 @@ class PropelBundle extends Bundle
|
||||||
if ($this->container->getParameter('propel.logging')) {
|
if ($this->container->getParameter('propel.logging')) {
|
||||||
$this->configureLogging();
|
$this->configureLogging();
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {}
|
} catch( \Exception $e ) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,6 +45,11 @@ class PropelBundle extends Bundle
|
||||||
*/
|
*/
|
||||||
public function build(ContainerBuilder $container)
|
public function build(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
|
parent::build($container);
|
||||||
|
|
||||||
|
if ($container->hasExtension('security')) {
|
||||||
|
$container->getExtension('security')->addUserProviderFactory(new PropelFactory('propel', 'propel.security.user.provider'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configureConnections()
|
protected function configureConnections()
|
||||||
|
|
Loading…
Reference in a new issue