Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2829239

Browse filesBrowse files
committed
Merge branch '2.8'
* 2.8: Added UserLoaderInterface for loading users through Doctrine. Fix the detection of the deprecated usage of the ValidationListener Use entry_type instead of type [Form] Fix missing notice for deprecated `type` [DI] Autowiring: w/a https://bugs.php.net/62715
2 parents cfb15ff + 72c6c61 commit 2829239
Copy full SHA for 2829239

File tree

Expand file treeCollapse file tree

8 files changed

+102
-11
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+102
-11
lines changed

‎src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ public function loadUserByUsername($username)
5454
if (null !== $this->property) {
5555
$user = $this->repository->findOneBy(array($this->property => $username));
5656
} else {
57-
if (!$this->repository instanceof UserProviderInterface) {
58-
throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement UserProviderInterface.', get_class($this->repository)));
57+
if (!$this->repository instanceof UserLoaderInterface) {
58+
if (!$this->repository instanceof UserProviderInterface) {
59+
throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface.', get_class($this->repository)));
60+
}
61+
62+
@trigger_error('Implementing loadUserByUsername from Symfony\Component\Security\Core\User\UserProviderInterface is deprecated since version 2.8 and will be removed in 3.0. Implement the Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface instead.', E_USER_DEPRECATED);
5963
}
6064

6165
$user = $this->repository->loadUserByUsername($username);
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Security\User;
13+
14+
use Symfony\Component\Security\Core\User\UserInterface;
15+
16+
/**
17+
* Represents a class that loads UserInterface objects from Doctrine source for the authentication system.
18+
*
19+
* This interface is meant to facilitate the loading of a User from Doctrine source using a custom method.
20+
* If you want to implement your own logic of retrieving the user from Doctrine your repository should implement this
21+
* interface.
22+
*
23+
* @see UserInterface
24+
*
25+
* @author Michal Trojanowski <michal@kmt-studio.pl>
26+
*/
27+
interface UserLoaderInterface
28+
{
29+
/**
30+
* Loads the user for the given username.
31+
*
32+
* This method must return null if the user is not found.
33+
*
34+
* @param string $username The username
35+
*
36+
* @return UserInterface|null
37+
*/
38+
public function loadUserByUsername($username);
39+
}

‎src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,39 @@ public function testSupportProxy()
8989
$this->assertTrue($provider->supportsClass(get_class($user2)));
9090
}
9191

92+
public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided()
93+
{
94+
$repository = $this->getMock('\Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface');
95+
$repository->expects($this->once())
96+
->method('loadUserByUsername')
97+
->with('name')
98+
->willReturn(
99+
$this->getMock('\Symfony\Component\Security\Core\User\UserInterface')
100+
);
101+
102+
$provider = new EntityUserProvider(
103+
$this->getManager($this->getObjectManager($repository)),
104+
'Symfony\Bridge\Doctrine\Tests\Fixtures\User'
105+
);
106+
107+
$provider->loadUserByUsername('name');
108+
}
109+
110+
/**
111+
* @expectedException \InvalidArgumentException
112+
*/
113+
public function testLoadUserByUserNameShouldDeclineInvalidInterface()
114+
{
115+
$repository = $this->getMock('\Symfony\Component\Security\Core\User\AdvancedUserInterface');
116+
117+
$provider = new EntityUserProvider(
118+
$this->getManager($this->getObjectManager($repository)),
119+
'Symfony\Bridge\Doctrine\Tests\Fixtures\User'
120+
);
121+
122+
$provider->loadUserByUsername('name');
123+
}
124+
92125
private function getManager($em, $name = null)
93126
{
94127
$manager = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
@@ -100,6 +133,18 @@ private function getManager($em, $name = null)
100133
return $manager;
101134
}
102135

136+
private function getObjectManager($repository)
137+
{
138+
$em = $this->getMockBuilder('\Doctrine\Common\Persistence\ObjectManager')
139+
->setMethods(array('getClassMetadata', 'getRepository'))
140+
->getMockForAbstractClass();
141+
$em->expects($this->any())
142+
->method('getRepository')
143+
->willReturn($repository);
144+
145+
return $em;
146+
}
147+
103148
private function createSchema($em)
104149
{
105150
$schemaTool = new SchemaTool($em);

‎src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ private function completeDefinition($id, Definition $definition)
9191
try {
9292
$value = $this->createAutowiredDefinition($typeHint, $id);
9393
} catch (RuntimeException $e) {
94-
if (!$parameter->isDefaultValueAvailable()) {
94+
if ($parameter->allowsNull()) {
95+
$value = null;
96+
} elseif ($parameter->isDefaultValueAvailable()) {
97+
$value = $parameter->getDefaultValue();
98+
} else {
9599
throw $e;
96100
}
97-
98-
$value = $parameter->getDefaultValue();
99101
}
100102
}
101103
} catch (\ReflectionException $reflectionException) {

‎src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public function configureOptions(OptionsResolver $resolver)
9292
if (null !== $value) {
9393
@trigger_error('The form option "type" is deprecated since version 2.8 and will be removed in 3.0. Use "entry_type" instead.', E_USER_DEPRECATED);
9494
}
95+
96+
return $value;
9597
};
9698
$entryType = function (Options $options) {
9799
if (null !== $options['type']) {
@@ -123,6 +125,7 @@ public function configureOptions(OptionsResolver $resolver)
123125
'delete_empty' => false,
124126
));
125127

128+
$resolver->setNormalizer('type', $typeNormalizer);
126129
$resolver->setNormalizer('options', $optionsNormalizer);
127130
$resolver->setNormalizer('entry_options', $entryOptionsNormalizer);
128131
}

‎src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function testRest()
195195
public function testCollection()
196196
{
197197
$form = $this->factory->createNamed('names', 'Symfony\Component\Form\Extension\Core\Type\CollectionType', array('a', 'b'), array(
198-
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
198+
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
199199
));
200200

201201
$this->assertWidgetMatchesXpath($form->createView(), array(),
@@ -213,7 +213,7 @@ public function testCollection()
213213
public function testEmptyCollection()
214214
{
215215
$form = $this->factory->createNamed('names', 'Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
216-
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
216+
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
217217
));
218218

219219
$this->assertWidgetMatchesXpath($form->createView(), array(),

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CollectionTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
1919
public function testContainsNoChildByDefault()
2020
{
2121
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
22-
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
22+
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
2323
));
2424

2525
$this->assertCount(0, $form);
@@ -293,10 +293,10 @@ public function testPrototypeDefaultLabel()
293293
public function testPrototypeData()
294294
{
295295
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
296-
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
297296
'allow_add' => true,
298297
'prototype' => true,
299298
'prototype_data' => 'foo',
299+
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
300300
'entry_options' => array(
301301
'data' => 'bar',
302302
),

‎src/Symfony/Component/Security/Core/User/UserProviderInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/User/UserProviderInterface.php
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ interface UserProviderInterface
4343
*
4444
* @return UserInterface
4545
*
46-
* @see UsernameNotFoundException
47-
*
4846
* @throws UsernameNotFoundException if the user is not found
4947
*/
5048
public function loadUserByUsername($username);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.