Developed with love by KnpLabs Hire us for your project!
0

user-bundle

by msgphp

[READ-ONLY] A new Symfony user bundle

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
  • Disabled / enabled users
  • User roles
  • User attribute values
  • User secondary e-mails

Blog posts

Configuration

<?php
// config/packages/msgphp.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,
        ],
    ]);
};

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.

MIT License

Copyright (c) 2017 Roland Franssen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.