2017 © Pedro Peláez
 

symfony-bundle current-user-bundle

Symfony bundle for fetching the user which is currently logged in

image

dyvelop/current-user-bundle

Symfony bundle for fetching the user which is currently logged in

  • Monday, September 5, 2016
  • by fdyckhoff
  • Repository
  • 1 Watchers
  • 1 Stars
  • 182 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

Build Status, (*1)

Dyvelop Current User Bundle

Symfony bundle to fetch the user which is currently logged in., (*2)

Installation

Step 1: Download

Download via Composer, (*3)

composer require dyvelop/current-user-bundle

Step 2: Enable Bundle

Enable the Bundle in the app/AppKernel.php file in your Symfony project:, (*4)

// File: app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Dyvelop\CurrentUserBundle\DyvelopCurrentUserBundle(),
        );

        return $bundles;
    }
}

Usage

Current User Provider

Mainly this bundle implements a service named dyvelop.current_user.provider which provides the current user:, (*5)

// fetch current user (the result is NULL when no one is logged in)
$user = $this->container->get('dyvelop.current_user.provider')->getUser();

You may use the CurrentUserAware interface and CurrentUserTrait helper to inject it into any other service., (*6)

Doctrine Annotation

Secondly, this bundle provides a Doctrine Annotation and Driver to inject the Current User into an entity via lifecycle callbacks:, (*7)

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Dyvelop\CurrentUserBundle\Annotation as Dyvelop;

class Article
{
    /**
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=true)
     * @Dyvelop\CurrentUser(prePersist=true)
     */
    protected $author;
}

In this example the current user will be set automatically as author of an article before persisting it to the database., (*8)

Currently, only the prePersist and preUpdate lifecycle callbacks are implemented. Feel free to contribute some more ;), (*9)

The Versions

05/09 2016

dev-master

9999999-dev

Symfony bundle for fetching the user which is currently logged in

  Sources   Download

MIT

The Requires

 

The Development Requires

by Franziska Dyckhoff

05/09 2016

v1.0.0-alpha

1.0.0.0-alpha

Symfony bundle for fetching the user which is currently logged in

  Sources   Download

MIT

The Requires

 

The Development Requires

by Franziska Dyckhoff