Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lib
unicaen
app
Commits
96f55e65
Commit
96f55e65
authored
9 years ago
by
Bertrand Gauthier
Browse files
Options
Downloads
Patches
Plain Diff
Toilettage indolore du listener Doctrine Historique.
parent
4da3a753
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/UnicaenApp/ORM/Event/Listeners/HistoriqueListener.php
+15
-24
15 additions, 24 deletions
src/UnicaenApp/ORM/Event/Listeners/HistoriqueListener.php
with
15 additions
and
24 deletions
src/UnicaenApp/ORM/Event/Listeners/HistoriqueListener.php
+
15
−
24
View file @
96f55e65
<?php
namespace
UnicaenApp\ORM\Event\Listeners
;
use
RuntimeException
;
use
UnicaenAuth\Entity\Db\AbstractUser
;
use
Zend\ServiceManager\ServiceLocatorAwareInterface
;
use
Zend\ServiceManager\ServiceLocatorAwareTrait
;
...
...
@@ -8,14 +9,18 @@ use Doctrine\ORM\Event\LifecycleEventArgs;
use
Doctrine\ORM\Event\PreUpdateEventArgs
;
use
Doctrine\ORM\Events
;
use
Doctrine\Common\EventSubscriber
;
use
Common\Exception\RuntimeException
;
use
UnicaenApp\Entity\HistoriqueAwareInterface
;
/**
* Listener Doctrine permettant l'ajout automatique de l'heure de création/modification
* et de l'auteur de création/modification de toute entité avant qu'elle soit persistée.
* Listener Doctrine.
*
* Modifie automatiquement l'heure et l'auteur de la création/modification
* de tout enregistrement dont la classe implémente HistoriqueAwareInterface.
*
* Déclenchement : avant que l'enregistrement ne soit persisté (création) ou mis à jour (update).
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
* @see HistoriqueAwareInterface
*/
class
HistoriqueListener
implements
EventSubscriber
,
ServiceLocatorAwareInterface
{
...
...
@@ -26,35 +31,30 @@ class HistoriqueListener implements EventSubscriber, ServiceLocatorAwareInterfac
*/
protected
$identity
;
/**
*
* @param LifecycleEventArgs $args
*
* @return
type
* @throws RuntimeException
* @return
void
* @throws RuntimeException
Aucun utilisateur connecté disponible pour la gestion de l'historique
*/
protected
function
updateHistorique
(
LifecycleEventArgs
$args
)
{
$em
=
$args
->
getEntityManager
();
$entity
=
$args
->
getEntity
();
$user
=
null
;
// l'entité doit implémenter l'interface requise
if
(
!
$entity
instanceof
HistoriqueAwareInterface
)
{
return
;
}
/* @var $entity \UnicaenApp\Entity\HistoriqueAwareInterface */
// l'utilisateur connecté sera l'auteur de la création/modification
$user
=
null
;
if
((
$identity
=
$this
->
getIdentity
()))
{
if
(
isset
(
$identity
[
'db'
])
&&
$identity
[
'db'
]
instanceof
AbstractUser
)
{
$user
=
$identity
[
'db'
];
/* @var $user AbstractUser */
}
}
if
(
null
===
$user
)
{
throw
new
RuntimeException
(
"Aucun utilisateur connecté disponible pour la gestion de l'historique."
);
}
...
...
@@ -86,8 +86,6 @@ class HistoriqueListener implements EventSubscriber, ServiceLocatorAwareInterfac
}
}
/**
* @param LifecycleEventArgs $args
*/
...
...
@@ -96,8 +94,6 @@ class HistoriqueListener implements EventSubscriber, ServiceLocatorAwareInterfac
$this
->
updateHistorique
(
$args
);
}
/**
* @param PreUpdateEventArgs $args
*/
...
...
@@ -106,13 +102,11 @@ class HistoriqueListener implements EventSubscriber, ServiceLocatorAwareInterfac
$this
->
updateHistorique
(
$args
);
}
/**
* Injecte l'identité authentifiée courante.
*
* @param mixed $identity
*
* @return \Common\ORM\Event\Listeners\Histo
* @return self
*/
public
function
setIdentity
(
$identity
)
{
...
...
@@ -121,9 +115,8 @@ class HistoriqueListener implements EventSubscriber, ServiceLocatorAwareInterfac
return
$this
;
}
/**
* Retourne l'identité authentifiée courante.
*
* @return mixed
*/
...
...
@@ -139,8 +132,6 @@ class HistoriqueListener implements EventSubscriber, ServiceLocatorAwareInterfac
return
$this
->
identity
;
}
/**
* {@inheritdoc}
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment