darkling / nette-identity-doctrine
Integration of entities implementing IIdentity in Nette 3
Installs: 720
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:nette-addon
Requires
- php: >=7.4
- doctrine/orm: ^2.6
- nette/di: ^3.0
- nette/http: ^3.0
- nette/security: ^3.0
Requires (Dev)
- consistence/coding-standard: ^3.10
- nette/bootstrap: ^3.0
- nettrine/orm: ^0.5
- phpstan/phpstan: ^0.12
- phpstan/phpstan-nette: ^0.12
- phpstan/phpstan-strict-rules: ^0.12
- phpunit/phpunit: ^7.5
- slevomat/coding-standard: 6.2 as 6.0.99
- tracy/tracy: ^3.0
Suggests
- nettrine/orm: Well-integrated Doctrine2 ORM for Nette Framework
This package is auto-updated.
Last update: 2024-11-10 06:23:03 UTC
README
Nette addon for using Doctrine 2 entities directly as Nette identity. Based on Majkl578/nette-identity-doctrine
Motivation
If you are using Nette 3 and Doctrine 2 together, you will sooner or later want to use some of your entities also as identity, because it is practical.
Fortunately, this addon is here to help you with this task!
Requirements
- PHP 7.4+
- Nette 3
- Doctrine ORM 2.6+
Installation
-
Install via composer:
composer require darkling/nette-identity-doctrine
-
Register extension in your configuration file in extensions section:
extensions: - Darkling\Doctrine2Identity\DI\IdentityExtension
-
Delete cache.
You're done. ;)
Usage
Imagine you have an application where you're implementing authentication.
All you have is a regular entity for the user in your application.
Now you want to implement the authentication itself - you need to have an identity.
The only thing you have to do is to implement Nette\Security\IIdentity
on your user entity,
so you get something like this:
use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity */ class UserEntity implements IIdentity { /** @ORM\Column(type="integer") @ORM\Id @ORM\GeneratedValue */ private $id; /** @ORM\Column */ private $name; ... other properties, getters & setters /* implementation of IIdentity */ public function getId() { return $this->id; } public function getRoles() { return []; } }
(Notice the empty getRoles() method. That is due to the requirement of IIdentity. If you don't use authorization, unfortunately, it can't be omitted, sorry.)
That's all. Everything is automatic! And you can even use entities with composite identifiers!
Issues
In case of any problems, just leave an issue here on GitHub (or, better, send a pull request).