Skip to content

Commit

Permalink
[TASK] Use PHP attributes for event listener registration
Browse files Browse the repository at this point in the history
  • Loading branch information
ayacoo committed Sep 29, 2024
1 parent 6e3af58 commit ff0c042
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
10 changes: 4 additions & 6 deletions Classes/EventListener/AfterFileAddedEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
namespace Ayacoo\AwsMeta\EventListener;

use Ayacoo\AwsMeta\Service\AwsImageRecognizeService;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Exception;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Resource\Event\AfterFileAddedEvent;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\MetaDataAspect;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;

#[AsEventListener(
identifier: 'ayacoo/aws-meta/after-file-added-event-listener'
)]
class AfterFileAddedEventListener
{
private array $extConf;
Expand All @@ -27,9 +29,6 @@ public function __construct(
$this->extConf = $this->extensionConfiguration->get('aws_meta') ?? [];
}

/**
* @throws Exception
*/
public function setMetadata(AfterFileAddedEvent $event): AfterFileAddedEvent
{
if (!$this->hasAllAwsSettings()) {
Expand All @@ -43,7 +42,6 @@ public function setMetadata(AfterFileAddedEvent $event): AfterFileAddedEvent
$extension = strtolower($file->getExtension());
$imageExtensions = ['jpg', 'png'];
if (in_array($extension, $imageExtensions, true) && $file->getPublicUrl() !== null) {
/** @var MetaDataAspect $metaData */
$metaData = $file->getMetaData();
$keywords = $this->awsImageRecognizeService->detectLabels($filePath);
if ($keywords !== '') {
Expand Down
6 changes: 0 additions & 6 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,3 @@ services:
Ayacoo\AwsMeta\:
resource: '../Classes/*'
exclude: '../Classes/Domain/Model/*'
Ayacoo\AwsMeta\EventListener\AfterFileAddedEventListener:
tags:
- name: event.listener
identifier: ayacoo/aws-meta/after-file-added-event-listener
event: TYPO3\CMS\Core\Resource\Event\AfterFileAddedEvent
method: 'setMetadata'

0 comments on commit ff0c042

Please sign in to comment.