/user-bundle

[READ-ONLY] A new Symfony user bundle

Primary LanguagePHPMIT LicenseMIT

User Bundle

A new Symfony bundle for basic user management.

Latest Stable Version

This package is part of the Message driven PHP project.

MsgPHP is a project that aims to provide (common) message based domain layers for your application. It has a low development time overhead and avoids being overly opinionated.

Installation

composer require msgphp/user-bundle

Features

  • Symfony 3.4 / 4.0 ready
  • Doctrine persistence
  • Symfony console commands
  • Symfony security infrastructure
  • Symfony validators
  • Credential independent (supports e-mail, nickname, etc.)
  • Multiple username / credential support
  • Primary and secondary user e-mails
  • Disabled / enabled users
  • User roles
  • User attribute values

Blog Posts

Configuration

<?php
// config/packages/msgphp_user.php

use MsgPhp\User\Entity\User;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return function (ContainerConfigurator $container) {
    $container->extension('msgphp_user', [
        'class_mapping' => [
            User::class => \App\Entity\User\User::class,
        ],
    ]);
};

Feeling Lazy?

composer require annot form validator twig security simple-bus/symfony-bridge orm
composer require maker server --dev
bin/console make:user

And be done.

Usage

Repositories from MsgPhp\User\Infra\Doctrine\Repository\* are registered as a service. Corresponding domain interfaces from MsgPhp\User\Repository\* are aliased.

Minimal configuration:

# config/packages/doctrine.yaml

doctrine:
    orm:
        mappings:
            app:
                dir: '%kernel.project_dir%/src/Entity'
                type: annotation
                prefix: App\Entity
  • Requires doctrine/orm

Command handlers from MsgPhp\User\Command\* are registered as a service.

  • Requires DoctrineBundle + doctrine/orm

Security infrastructure from MsgPhp\User\Infra\Security\* is registered as a service.

In practice the security user is decoupled from your domain entity user. An approach described here.

  • MsgPhp\User\Infra\Security\SecurityUser implementing Symfony\Component\Security\Core\User\UserInterface
  • App\Entity\User\User extending MsgPhp\User\Entity\User

Minimal configuration:

# config/packages/security.yaml

security:
    encoders:
        MsgPhp\User\Infra\Security\SecurityUser: bcrypt

    providers:
         msgphp_user: { id: MsgPhp\User\Infra\Security\SecurityUserProvider }

    firewalls:
        main:
            provider: msgphp_user
            anonymous: ~
  • Requires DoctrineBundle + doctrine/orm
  • Suggests SensioFrameworkExtraBundle to enable the parameter converter

Console commands from MsgPhp\User\Infra\Console\Command\* are registered as a service.

  • Requires DoctrineBundle + doctrine/orm
  • Requires SimpleBusCommandBusBundle

Form types from MsgPhp\User\Infra\Form\Type\* are registered as a service.

Validators from MsgPhp\User\Infra\Validator\* are registered as a service.

  • Requires DoctrineBundle + doctrine/orm

Documentation

Contributing

This repository is READ ONLY. Issues and pull requests should be submitted in the main development repository.