mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,36 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Doctrine\Event;
|
||||
|
||||
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\EventSubscriber;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
|
||||
class TrackCreateUpdateSubscriber implements EventSubscriber
|
||||
{
|
||||
private Security $security;
|
||||
|
||||
/**
|
||||
* @param Security $security
|
||||
*/
|
||||
public function __construct(Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
public function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
Events::prePersist,
|
||||
Events::preUpdate
|
||||
Events::preUpdate,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -41,7 +42,7 @@ class TrackCreateUpdateSubscriber implements EventSubscriber
|
||||
if ($object instanceof TrackCreationInterface
|
||||
&& $this->security->getUser() instanceof User) {
|
||||
$object->setCreatedBy($this->security->getUser());
|
||||
$object->setCreatedAt(new \DateTimeImmutable('now'));
|
||||
$object->setCreatedAt(new DateTimeImmutable('now'));
|
||||
}
|
||||
|
||||
$this->onUpdate($object);
|
||||
@@ -56,10 +57,10 @@ class TrackCreateUpdateSubscriber implements EventSubscriber
|
||||
|
||||
protected function onUpdate(object $object): void
|
||||
{
|
||||
if ($object instanceof TrackUpdateInterface
|
||||
if ($object instanceof TrackUpdateInterface
|
||||
&& $this->security->getUser() instanceof User) {
|
||||
$object->setUpdatedBy($this->security->getUser());
|
||||
$object->setUpdatedAt(new \DateTimeImmutable('now'));
|
||||
$object->setUpdatedAt(new DateTimeImmutable('now'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user