FOSUserBundle
FOSUserBundle copied to clipboard
[RFC] Compatibility with Symfony Flex
Symfony FOSUserBundle versions: dev-master
Description of the problem including expected versus actual behavior:
When trying to install FOSUB in a Symfony Flex project, the assets:install commands fails, which prevents the bundle from being installed (see log).
I'm not sure what the best solution would be here... As far as I could see, there are no current solutions for interactive configuration via Flex's bundle autoconfiguration system. However, most project rely on the doctrine ORM to store users, AFAIK.
Maybe a solution could be to provide a "dummy" driver that allows the default configuration to go through but prevents actually using the bundle until an actual driver has been configured? What do you think?
Steps to reproduce:
- Start a Symfony project using Symfony Flex
- composer require composer require friendsofsymfony/user-bundle
Provide logs (if relevant):
mlemoine@local ~/project $ composer require friendsofsymfony/user-bundle
Using version ^2.0@dev for friendsofsymfony/user-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 6 installs, 0 updates, 0 removals
- Installing symfony/templating (3.4.x-dev f333054): Downloading (100%)
- Installing symfony/options-resolver (3.4.x-dev c6db86e): Downloading (100%)
- Installing symfony/intl (3.4.x-dev fbdc2d8): Downloading (100%)
- Installing symfony/polyfill-intl-icu (dev-master d50e463): Downloading (100%)
- Installing symfony/form (3.4.x-dev f44a4a0): Downloading (100%)
- Installing friendsofsymfony/user-bundle (dev-master 039b826): Downloading (100%)
Detected auto-configuration settings for "friendsofsymfony/user-bundle"
Enabling the package as a Symfony bundle
Writing lock file
Generating autoload files
Executing script make cache-warmup [OK]
Executing script assets:install --symlink --relative %WEB_DIR% [KO]
[KO]
Script assets:install --symlink --relative %WEB_DIR% returned with error code 1
!!
!!
!!
!!
!! [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
!!
!! The child node "db_driver" at path "fos_user" must be configured.
!!
!!
!!
!!
!!
Installation failed, reverting ./composer.json to its original content.
Steps required to be able to install FOSUserBundle in a Symfony Flex project:
- Install
symfony/swiftmailer-bundle - Add the following configuration file in
etc/packages/foo.yaml:
framework:
templating: { engines: [twig] }
fos_user:
db_driver: orm
firewall_name: main
user_class: FOS\UserBundle\Model\User
from_email: {address: "fosub@localhost", sender_name: FOSUB}
use_flash_notifications: false
What I would recommend:
- Provide a dummy Database driver (
customwon't cut it as it doesn't work out-of-the-box) - Add
symfony/swiftmailer-bundleas a required dependency - Add a Symfony Flex recipe providing a default configuration working out-of-the-box
What do you think? I'm ready to start opening PRs if you think this is the way to go!
I also had to enable the "session" service
Inside config/packages/framework.yaml
framework:
session:
handler_id: session.handler.native_file
save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
templating:
engines: ['twig']
and had to create config/packages/fos_user.yaml with:
fos_user:
db_driver: orm
firewall_name: main
user_class: App\Entity\User
from_email:
address: "[email protected]"
sender_name: "Sender Name"
As we can find here, we have to define the mailer service.
On freshly installed SF3.3 with Flex i had to set:
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: App\Entity\User
from_email:
address: '%env(MAILER_USER_ADDRESS)%'
sender_name: '%env(MAILER_USER_NAME)%'
service:
mailer: 'fos_user.mailer.noop'
# mailer: 'fos_user.mailer.twig_swift' # Works as well
worked for me, I hope this will help you.
I don't want to add SwiftmailerBundle as a required dependency, as this would hurt anyone not using it (and Swiftmailer is not the only option to send emails, with the rise of tools like Sendgrid or Mandrill doing all the heavy work). This must stay an optional dependency.
However, I do want to improve the setup with Flex. I just haven't had time to do it yet.
Thanks @allemas It works for me
+1
Hello,
I am struggling to get this package working with Flex. Finding this issue I assume that it is currently not possible. As such I wont proceed yet until there is some new documentation for this that takes into consideration the new config directory and the service autowiring.
Is there any update?
@tip2tail I am using this following @allemas indications. You just have to create the configuration yaml before doing the composer require.
If using swiftmailer then you have to require it before fos-user.
May be fos_user.mailer.twig_swift should be a default fosub mailer service instead of fos_user.mailer.default? Then templating service won't be used any more by default.
See FOS\UserBundle\DependencyInjection\Configuration::addServiceSection
I don't want to add SwiftmailerBundle as a required dependency, as this would hurt anyone not using it (and Swiftmailer is not the only option to send emails, with the rise of tools like Sendgrid or Mandrill doing all the heavy work). This must stay an optional dependency.
@stof The dependency is optional, but the FOS mailer seems to require a Swift_Mailer instance according to PHPDoc:
/**
* Mailer constructor.
*
* @param \Swift_Mailer $mailer
* @param UrlGeneratorInterface $router
* @param EngineInterface $templating
* @param array $parameters
*/
public function __construct($mailer, UrlGeneratorInterface $router, EngineInterface $templating, array $parameters)
{
$this->mailer = $mailer;
$this->router = $router;
$this->templating = $templating;
$this->parameters = $parameters;
}
Forget my last comment, I read the code too fast.
Any news on this ?
Hi. Any news?