Skip to content

Commit ff1ef94

Browse files
committed
Make db_driver parameter optional with "no_driver" default value
1 parent 6d02c6c commit ff1ef94

File tree

7 files changed

+130
-13
lines changed

7 files changed

+130
-13
lines changed

DependencyInjection/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ public function getConfigTreeBuilder()
3434
$treeBuilder = new TreeBuilder();
3535
$rootNode = $treeBuilder->root('fos_user');
3636

37-
$supportedDrivers = array('orm', 'mongodb', 'couchdb', 'custom');
37+
$supportedDrivers = array('orm', 'mongodb', 'couchdb', 'custom', 'no_driver');
3838

3939
$rootNode
4040
->children()
4141
->scalarNode('db_driver')
42+
->defaultValue('no_driver')
4243
->validate()
4344
->ifNotInArray($supportedDrivers)
4445
->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers))
4546
->end()
4647
->cannotBeOverwritten()
47-
->isRequired()
4848
->cannotBeEmpty()
4949
->end()
5050
->scalarNode('user_class')->isRequired()->cannotBeEmpty()->end()

Model/GroupManagerNone.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.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 FOS\UserBundle\Model;
13+
14+
/**
15+
* Fallback Group Manager implementation when db_driver is not configured.
16+
*
17+
* @author Andrey F. Mindubaev <[email protected]>
18+
*/
19+
class GroupManagerNone extends GroupManager
20+
{
21+
public function deleteGroup(GroupInterface $group)
22+
{
23+
throw new \RuntimeException('The child node "db_driver" at path "fos_user" must be configured.');
24+
}
25+
26+
public function findGroupBy(array $criteria)
27+
{
28+
throw new \RuntimeException('The child node "db_driver" at path "fos_user" must be configured.');
29+
}
30+
31+
public function findGroups()
32+
{
33+
throw new \RuntimeException('The child node "db_driver" at path "fos_user" must be configured.');
34+
}
35+
36+
public function getClass()
37+
{
38+
throw new \RuntimeException('The child node "db_driver" at path "fos_user" must be configured.');
39+
}
40+
41+
public function updateGroup(GroupInterface $group)
42+
{
43+
throw new \RuntimeException('The child node "db_driver" at path "fos_user" must be configured.');
44+
}
45+
}

Model/UserManagerNone.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.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 FOS\UserBundle\Model;
13+
14+
/**
15+
* Fallback User Manager implementation when db_driver is not configured.
16+
*
17+
* @author Andrey F. Mindubaev <[email protected]>
18+
*/
19+
class UserManagerNone extends UserManager
20+
{
21+
public function deleteUser(UserInterface $user)
22+
{
23+
throw new \RuntimeException('The child node "db_driver" at path "fos_user" must be configured.');
24+
}
25+
26+
public function findUserBy(array $criteria)
27+
{
28+
throw new \RuntimeException('The child node "db_driver" at path "fos_user" must be configured.');
29+
}
30+
31+
public function findUsers()
32+
{
33+
throw new \RuntimeException('The child node "db_driver" at path "fos_user" must be configured.');
34+
}
35+
36+
public function getClass()
37+
{
38+
throw new \RuntimeException('The child node "db_driver" at path "fos_user" must be configured.');
39+
}
40+
41+
public function reloadUser(UserInterface $user)
42+
{
43+
throw new \RuntimeException('The child node "db_driver" at path "fos_user" must be configured.');
44+
}
45+
46+
public function updateUser(UserInterface $user)
47+
{
48+
throw new \RuntimeException('The child node "db_driver" at path "fos_user" must be configured.');
49+
}
50+
}

Resources/config/no_driver.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<services>
8+
<service id="fos_user.user_manager.default" class="FOS\UserBundle\Model\UserManagerNone" public="false">
9+
<argument type="service" id="fos_user.util.password_updater" />
10+
<argument type="service" id="fos_user.util.canonical_fields_updater" />
11+
</service>
12+
</services>
13+
</container>

Resources/config/no_driver_group.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<services>
8+
<service id="fos_user.group_manager.default" class="FOS\UserBundle\Model\GroupManagerNone" public="false" />
9+
</services>
10+
</container>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" ?>
2+
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
5+
http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
6+
7+
<class name="FOS\UserBundle\Model\User" />
8+
9+
<class name="FOS\UserBundle\Model\Group" />
10+
</constraint-mapping>

Tests/DependencyInjection/FOSUserExtensionTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,6 @@ protected function tearDown()
2626
$this->configuration = null;
2727
}
2828

29-
/**
30-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
31-
*/
32-
public function testUserLoadThrowsExceptionUnlessDatabaseDriverSet()
33-
{
34-
$loader = new FOSUserExtension();
35-
$config = $this->getEmptyConfig();
36-
unset($config['db_driver']);
37-
$loader->load(array($config), new ContainerBuilder());
38-
}
39-
4029
/**
4130
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
4231
*/

0 commit comments

Comments
 (0)