Skip to content

[RFC] Compatibility with Symfony Flex #2562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lemoinem opened this issue May 22, 2017 · 13 comments
Open

[RFC] Compatibility with Symfony Flex #2562

lemoinem opened this issue May 22, 2017 · 13 comments

Comments

@lemoinem
Copy link

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:

  1. Start a Symfony project using Symfony Flex
  2. 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.

@lemoinem
Copy link
Author

lemoinem commented May 22, 2017

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:

  1. Provide a dummy Database driver (custom won't cut it as it doesn't work out-of-the-box)
  2. Add symfony/swiftmailer-bundle as a required dependency
  3. 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!

@lemoinem lemoinem changed the title Compatibility with Symfony Flex [RFC] Compatibility with Symfony Flex May 28, 2017
@enlego
Copy link

enlego commented Jul 29, 2017

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"

@allemas
Copy link

allemas commented Oct 2, 2017

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.

@stof
Copy link
Member

stof commented Oct 2, 2017

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.

@allucardster
Copy link

Thanks @allemas It works for me

@stayeronglass
Copy link

+1

@tip2tail
Copy link

tip2tail commented Nov 3, 2017

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?

@jsampedro77
Copy link

@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.

@covex-nn
Copy link

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

@soullivaneuh
Copy link

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;
}

@soullivaneuh
Copy link

Forget my last comment, I read the code too fast.

@leup
Copy link

leup commented May 17, 2018

Any news on this ?

aligalipcamli added a commit to aligalipcamli/delivery-planner that referenced this issue Feb 8, 2019

Verified

This commit was signed with the committer’s verified signature.
illarionov Alexey Illarionov
@vladdnepr
Copy link

Hi. Any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests