diff --git a/DependencyInjection/Security/UserProvider/PropelFactory.php b/DependencyInjection/Security/UserProvider/PropelFactory.php new file mode 100644 index 0000000..daf5af3 --- /dev/null +++ b/DependencyInjection/Security/UserProvider/PropelFactory.php @@ -0,0 +1,51 @@ + + * + * 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 + */ +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() + ; + } +} \ No newline at end of file diff --git a/Form/ChoiceList/ModelChoiceList.php b/Form/ChoiceList/ModelChoiceList.php index 9af9627..35bfd60 100644 --- a/Form/ChoiceList/ModelChoiceList.php +++ b/Form/ChoiceList/ModelChoiceList.php @@ -204,11 +204,10 @@ class ModelChoiceList extends ObjectChoiceList $filterBy = 'filterBy' . current($this->identifier)->getPhpName(); // The initial query is cloned, so all additional filters are applied correctly. $query = clone $this->query; - $result = (array)$query - ->$filterBy( - $values - ) - ->find(); + $query + ->$filterBy($values) + ; + $result = iterator_to_array($query->find()); // Preserve the keys as provided by the values. $models = array(); foreach ($values as $index => $value) { @@ -424,10 +423,10 @@ class ModelChoiceList extends ObjectChoiceList return; } - $models = (array)$this->query->find(); + $models = iterator_to_array($this->query->find()); $preferred = array(); if ($this->preferredQuery instanceof ModelCriteria) { - $preferred = (array)$this->preferredQuery->find(); + $preferred = iterator_to_array($this->preferredQuery->find()); } try { diff --git a/PropelBundle.php b/PropelBundle.php index a6d46f5..6007914 100644 --- a/PropelBundle.php +++ b/PropelBundle.php @@ -10,6 +10,7 @@ namespace Propel\PropelBundle; +use Propel\PropelBundle\DependencyInjection\Security\UserProvider\PropelFactory; use Propel\Runtime\Propel; use Propel\Runtime\Connection\ConnectionManagerSingle; use Propel\Runtime\Connection\ConnectionManagerMasterSlave; @@ -35,7 +36,8 @@ class PropelBundle extends Bundle if ($this->container->getParameter('propel.logging')) { $this->configureLogging(); } - } catch (\Exception $e) {} + } catch( \Exception $e ) { + } } /** @@ -43,6 +45,11 @@ class PropelBundle extends Bundle */ 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()