AuditLogger.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Security\Acl\Domain;
  11. use Symfony\Component\Security\Acl\Model\AuditableEntryInterface;
  12. use Symfony\Component\Security\Acl\Model\EntryInterface;
  13. use Symfony\Component\Security\Acl\Model\AuditLoggerInterface;
  14. /**
  15. * Base audit logger implementation.
  16. *
  17. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  18. */
  19. abstract class AuditLogger implements AuditLoggerInterface
  20. {
  21. /**
  22. * Performs some checks if logging was requested.
  23. *
  24. * @param bool $granted
  25. * @param EntryInterface $ace
  26. */
  27. public function logIfNeeded($granted, EntryInterface $ace)
  28. {
  29. if (!$ace instanceof AuditableEntryInterface) {
  30. return;
  31. }
  32. if ($granted && $ace->isAuditSuccess()) {
  33. $this->doLog($granted, $ace);
  34. } elseif (!$granted && $ace->isAuditFailure()) {
  35. $this->doLog($granted, $ace);
  36. }
  37. }
  38. /**
  39. * This method is only called when logging is needed.
  40. *
  41. * @param bool $granted
  42. * @param EntryInterface $ace
  43. */
  44. abstract protected function doLog($granted, EntryInterface $ace);
  45. }