Skip to content

Commit

Permalink
feat: replace doctrine annotation to php attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
saifulferoz committed Sep 14, 2024
1 parent 2da885a commit 7c22a94
Show file tree
Hide file tree
Showing 36 changed files with 98 additions and 177 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest ]
php-versions: [ '8.0', '8.1', '8.2' ]
php-versions: [ '8.0', '8.1', '8.2','8.3' ]

steps:
- name: Checkout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
* with this source code in the file LICENSE.
*/

namespace Xiidea\EasyAuditBundle\Annotation;
namespace Xiidea\EasyAuditBundle\Attribute;

/**
* Annotation for ORM Subscribed Event.
*
* @Annotation
* @Target({"CLASS"})
* Attribute for ORM Subscribed Event.
*
* @author Roni Saha <[email protected]>
*/

#[\Attribute(\Attribute::TARGET_CLASS)]
/* @final */ class SubscribeDoctrineEvents
{
public $events = array();
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Compiler/LoggerFactoryPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

class LoggerFactoryPass implements CompilerPassInterface
{
#[\Override]
public function process(ContainerBuilder $container): void
{
if (false === $container->hasDefinition('xiidea.easy_audit.logger_factory')) {
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Compiler/MonologLoggerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class MonologLoggerPass implements CompilerPassInterface
{
#[\Override]
public function process(ContainerBuilder $container): void
{
if (false === $container->hasAlias('logger')) {
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Compiler/ResolverFactoryPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

class ResolverFactoryPass implements CompilerPassInterface
{
#[\Override]
public function process(ContainerBuilder $container): void
{
if (false === $container->hasDefinition('xiidea.easy_audit.event_resolver_factory')) {
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Compiler/SubscriberPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

class SubscriberPass implements CompilerPassInterface
{
#[\Override]
public function process(ContainerBuilder $container): void
{
if (false === $container->hasDefinition('xiidea.easy_audit.event_listener')) {
Expand Down
3 changes: 2 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder(self::ROOT_NODE_NAME);
Expand Down Expand Up @@ -148,7 +149,7 @@ public static function throwExceptionOnInvalid($invalid)

public static function appendChannelTypes($element, &$isExclusiveList, &$elements = array())
{
$isExclusiveItem = 0 === strpos($element, '!');
$isExclusiveItem = str_starts_with($element, '!');

self::throwExceptionOnInvalid(!$isExclusiveItem === $isExclusiveList);

Expand Down
2 changes: 2 additions & 0 deletions DependencyInjection/XiideaEasyAuditExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class XiideaEasyAuditExtension extends Extension implements PrependExtensionInte
/**
* {@inheritdoc}
*/
#[\Override]
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
Expand Down Expand Up @@ -72,6 +73,7 @@ protected function loadDefaultResolverServices($config, LoaderInterface $loader)
* Allow an extension to prepend the extension configurations.
* @param ContainerBuilder $container
*/
#[\Override]
public function prepend(ContainerBuilder $container): void
{
$prependConfig = $this->getExtendedConfig($container);
Expand Down
11 changes: 1 addition & 10 deletions Events/DoctrineObjectEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,8 @@

class DoctrineObjectEvent extends Event
{
private $identity;

/**
* @var LifecycleEventArgs
*/
private $lifecycleEventArgs;

public function __construct(LifecycleEventArgs $lifecycleEventArgs, $identity)
public function __construct(private LifecycleEventArgs $lifecycleEventArgs, private $identity)
{
$this->lifecycleEventArgs = $lifecycleEventArgs;
$this->identity = $identity;
}

/**
Expand Down
13 changes: 1 addition & 12 deletions Listener/LogEventsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,8 @@

class LogEventsListener
{
/**
* @var LoggerFactory
*/
private $loggerFactory;
/**
* @var \Xiidea\EasyAuditBundle\Resolver\EventResolverFactory
*/
private $resolverFactory;

public function __construct(LoggerFactory $loggerFactory, EventResolverFactory $resolverFactory)
public function __construct(private LoggerFactory $loggerFactory, private EventResolverFactory $resolverFactory)
{
$this->loggerFactory = $loggerFactory;
$this->resolverFactory = $resolverFactory;
}

public function resolveEventHandler(Event $event, $eventName)
Expand Down
9 changes: 2 additions & 7 deletions Logger/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@ class Logger implements LoggerInterface
{
private $entityDeleteLogs = [];

/**
* @var \Doctrine\Persistence\ManagerRegistry
*/
private $doctrine;

public function __construct(ManagerRegistry $doctrine)
public function __construct(private ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}

#[\Override]
public function log(AuditLog $event = null)
{
if (empty($event)) {
Expand Down
10 changes: 2 additions & 8 deletions Logger/LoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ class LoggerFactory
/** @var LoggerInterface[] */
private static $loggers = array();

private $loggersChannel;

private $debug = false;

public function __construct(array $channel = array())
public function __construct(private array $loggersChannel = array())
{
$this->loggersChannel = $channel;
}

/**
Expand Down Expand Up @@ -116,10 +113,7 @@ protected function isValidLoggerForThisEvent(BaseAuditLog $eventInfo, $logger, $
return $logger instanceof LoggerInterface && $this->isChannelRegisterWithLogger($id, $eventInfo->getLevel());
}

/**
* @param mixed $debug
*/
public function setDebug($debug)
public function setDebug(mixed $debug)
{
$this->debug = $debug;
}
Expand Down
9 changes: 2 additions & 7 deletions Logger/MonologLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@

class MonologLogger implements LoggerInterface
{
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;

private static $ignoreProperties = array('description', 'id', 'level');

public function __construct(\Psr\Log\LoggerInterface $logger)
public function __construct(private \Psr\Log\LoggerInterface $logger)
{
$this->logger = $logger;
}

#[\Override]
public function log(AuditLog $event = null)
{
if (null === $event) {
Expand Down
5 changes: 1 addition & 4 deletions Model/BaseAuditLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,7 @@ public function getImpersonatingUser()
return $this->impersonatingUser;
}

/**
* @param mixed $impersonatingUser
*/
public function setImpersonatingUser($impersonatingUser)
public function setImpersonatingUser(mixed $impersonatingUser)
{
$this->impersonatingUser = $impersonatingUser;
}
Expand Down
1 change: 1 addition & 0 deletions Resolver/DefaultEventResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DefaultEventResolver implements EventResolverInterface
*
* @return array
*/
#[\Override]
public function getEventLogInfo(Event $event, $eventName)
{
return array(
Expand Down
1 change: 1 addition & 0 deletions Resolver/DoctrineObjectEventResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class DoctrineObjectEventResolver implements EventResolverInterface
*
* @throws \ReflectionException
*/
#[\Override]
public function getEventLogInfo(Event $event, $eventName)
{
if (!$event instanceof DoctrineObjectEvent) {
Expand Down
18 changes: 3 additions & 15 deletions Resolver/EventResolverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ class EventResolverFactory extends UserAwareComponent
*/
private $entityEventResolver;

private $resolverEventMap = array();

private $debug = false;
private $userProperty;
private $entityClass;

/**
* EventResolverFactory constructor.
Expand All @@ -44,11 +40,8 @@ class EventResolverFactory extends UserAwareComponent
* @param $userProperty
* @param $entityClass
*/
public function __construct(array $resolverEventMap = array(), $userProperty = 'userIdentifier', $entityClass = BaseAuditLog::class)
public function __construct(private array $resolverEventMap = array(), private $userProperty = 'userIdentifier', private $entityClass = BaseAuditLog::class)
{
$this->resolverEventMap = $resolverEventMap;
$this->userProperty = $userProperty;
$this->entityClass = $entityClass;
}

/**
Expand Down Expand Up @@ -195,11 +188,9 @@ public function addCustomResolver($id, $resolver)
}

/**
* @param mixed $resolver
*
* @throws \Exception
*/
public function setCommonResolver($resolver)
public function setCommonResolver(mixed $resolver)
{
if (!$resolver instanceof EventResolverInterface) {
$this->commonResolver = $this->handleException(new InvalidServiceException(
Expand Down Expand Up @@ -280,10 +271,7 @@ protected function setImpersonatingUser(BaseAuditLog $entity, $userProperty)
}
}

/**
* @param mixed $debug
*/
public function setDebug($debug)
public function setDebug(mixed $debug)
{
$this->debug = $debug;
}
Expand Down
9 changes: 2 additions & 7 deletions Resolver/UserEventCommand/InteractiveLoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,16 @@

class InteractiveLoginCommand extends UserLoginCommand
{
/**
* @var UserAwareComponent
*/
private $userAwareComponent;

public function __construct(UserAwareComponent $userAwareComponent)
public function __construct(private UserAwareComponent $userAwareComponent)
{
$this->userAwareComponent = $userAwareComponent;
}

/**
* @param $event
*
* @return mixed
*/
#[\Override]
public function resolve($event)
{
return $this->getEventDetailsArray($this->userAwareComponent->getUsername());
Expand Down
2 changes: 2 additions & 0 deletions Resolver/UserEventCommand/UserLoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ abstract class UserLoginCommand extends ResolverCommand
/**
* @return string
*/
#[\Override]
public function getType()
{
return 'User Logged in';
Expand All @@ -24,6 +25,7 @@ public function getType()
/**
* @return string
*/
#[\Override]
public function getTemplate()
{
return "User '%s' Logged in Successfully";
Expand Down
1 change: 1 addition & 0 deletions Resolver/UserEventResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct()
*
* @return array
*/
#[\Override]
public function getEventLogInfo(Event $event, $eventName)
{
$this->default = array(
Expand Down
1 change: 0 additions & 1 deletion Resources/config/doctrine_services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ services:
arguments: ['%xiidea.easy_audit.doctrine_objects%']
calls:
- [ setDispatcher,[ '@event_dispatcher' ] ]
- [ setAnnotationReader,[ '@annotation_reader' ] ]
tags:
- { name: doctrine.event_listener, event: preRemove }
- { name: doctrine.event_listener, event: postUpdate }
Expand Down
9 changes: 2 additions & 7 deletions Subscriber/DoctrineDeleteEventLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@

class DoctrineDeleteEventLogger implements EventSubscriberInterface
{
/**
* @var Logger
*/
private $logger;

/**
* DoctrineDeleteEventLogger constructor.
*
* @param Logger $logger
*/
public function __construct(Logger $logger)
public function __construct(private Logger $logger)
{
$this->logger = $logger;
}

public function savePendingLogs()
Expand All @@ -41,6 +35,7 @@ public function savePendingLogs()
/**
* @return array
*/
#[\Override]
public static function getSubscribedEvents(): array
{
return [
Expand Down
Loading

0 comments on commit 7c22a94

Please sign in to comment.