msgphp/user-bundle

Basic user management (the `User` domain)

Installs: 1 227

Dependents: 1

Suggesters: 0

Stars: 50

Watchers: 6

Forks: 4

Type:symfony-bundle

v0.3.1 2018-04-14 10:24 UTC

README

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

With DoctrineBundle

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

With SimpleBusCommandBusBundle

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

  • Requires DoctrineBundle + doctrine/orm

With SecurityBundle

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

With symfony/console

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

  • Requires DoctrineBundle + doctrine/orm
  • Requires SimpleBusCommandBusBundle

With symfony/form

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

With symfony/validator

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.