Skip to content

Commit

Permalink
Merge pull request #33 from akrys/v3-vorbereitung
Browse files Browse the repository at this point in the history
v3.0 Umstellung auf PHP 8.1
  • Loading branch information
akrys authored Dec 31, 2023
2 parents e47850d + 9c100d6 commit 8dda07d
Show file tree
Hide file tree
Showing 19 changed files with 247 additions and 161 deletions.
7 changes: 3 additions & 4 deletions lib/Cli/Read.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
*
* @author akrys
*/
class Read
extends rex_console_command
class Read extends rex_console_command
{

/**
* Konsolen-Aufruf konfigurieren.
*/
protected function configure()
protected function configure(): void
{
$this
->setName('mediapool_exif:read')
Expand All @@ -43,7 +42,7 @@ protected function configure()
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
$io = $this->getStyle($input, $output);
$io->title('Read EXIF data');
Expand Down
6 changes: 3 additions & 3 deletions lib/Enum/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*
* @author akrys
*/
class /* enum */ Format /* :string */
enum Format :string
{
const /*case*/ RAW = 'numeric';
const /*case*/ READABLE = 'readable';
case RAW = 'numeric';
case READABLE = 'readable';
}
84 changes: 84 additions & 0 deletions lib/Enum/IptcDefinitions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPEnum.php to edit this template
*/
namespace FriendsOfRedaxo\addon\MediapoolExif\Enum;

/**
*
* @author akrys
*/
enum IptcDefinitions
{
case DOCUMENT_TITLE; //2#005' | DocumentTitle
case URGENCY; //2#010' | Urgency
case CATEGORY; //2#015' | Category
case SUBCATEGORIES; //2#020' | Subcategories
case KEYWORDS; //2#025' | Keywords
case SPECIAL_INSTRUCTIONS; //2#040' | SpecialInstructions
case CREATION_DATE; //2#055' | CreationDate
case AUTHOR_BY_LINE; //2#080' | AuthorByline
case AUTHOR_TITLE; //2#085' | AuthorTitle
case CITY; //2#090' | City
case STATE; //2#095' | State
case COUNTRY; //2#101' | Country
case OTR; //2#103' | OTR
case HEADLINE; //2#105' | Headline
case SOURCE; //2#110' | Source
case PHOTO_SOURCE; //2#115' | PhotoSource
case COPYRIGHT; //2#116' | Copyright
case CAPTION; //2#120' | Caption
case CAPTION_WRITER; //2#122' | CaptionWriter

public function getCode(): string
{
return match ($this) {
self::DOCUMENT_TITLE => '2#005',
self::URGENCY => '2#010',
self::CATEGORY => '2#015',
self::SUBCATEGORIES => '2#020',
self::KEYWORDS => '2#025',
self::SPECIAL_INSTRUCTIONS => '2#040',
self::CREATION_DATE => '2#055',
self::AUTHOR_BY_LINE => '2#080',
self::AUTHOR_TITLE => '2#085',
self::CITY => '2#090',
self::STATE => '2#095',
self::COUNTRY => '2#101',
self::OTR => '2#103',
self::HEADLINE => '2#105',
self::SOURCE => '2#110',
self::PHOTO_SOURCE => '2#115',
self::COPYRIGHT => '2#116',
self::CAPTION => '2#120',
self::CAPTION_WRITER => '2#122',
};
}

public function getLabel(): string
{
return match ($this) {
self::DOCUMENT_TITLE => 'DocumentTitle',
self::URGENCY => 'Urgency',
self::CATEGORY => 'Category',
self::SUBCATEGORIES => 'Subcategories',
self::KEYWORDS => 'Keywords',
self::SPECIAL_INSTRUCTIONS => 'SpecialInstructions',
self::CREATION_DATE => 'CreationDate',
self::AUTHOR_BY_LINE => 'AuthorByline',
self::AUTHOR_TITLE => 'AuthorTitle',
self::CITY => 'City',
self::STATE => 'State',
self::COUNTRY => 'Country',
self::OTR => 'OTR',
self::HEADLINE => 'Headline',
self::SOURCE => 'Source',
self::PHOTO_SOURCE => 'PhotoSource',
self::COPYRIGHT => 'Copyright',
self::CAPTION => 'Caption',
self::CAPTION_WRITER => 'CaptionWriter',
};
}
}
6 changes: 3 additions & 3 deletions lib/Enum/MediaFetchMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*
* @author akrys
*/
class /*enum*/ MediaFetchMode /*:int*/
enum MediaFetchMode :int
{
const /*case*/ NULL_ONLY = 1000;
const /*case*/ ALL = 1001;
case NULL_ONLY = 1000;
case ALL = 1001;
}
17 changes: 8 additions & 9 deletions lib/Enum/ReturnMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
*/

namespace FriendsOfRedaxo\addon\MediapoolExif\Enum;

/**
Expand All @@ -19,13 +18,13 @@
*
* @author akrys
*/
class /*enum*/ ReturnMode /*:int*/
enum ReturnMode: int
{
const /*case*/ THROW_EXCEPTION = 1000; //should be default
const /*case*/ RETURN_NULL = 1001;
const /*case*/ RETURN_FALSE = 1002;
const /*case*/ RETURN_ZERO = 1003;
const /*case*/ RETURN_MINUS = 1004;
const /*case*/ RETURN_EMPTY_STRING = 1005;
const /*case*/ RETURN_EMPTY_ARRAY = 1006;
case THROW_EXCEPTION = 1000; //should be default
case RETURN_NULL = 1001;
case RETURN_FALSE = 1002;
case RETURN_ZERO = 1003;
case RETURN_MINUS = 1004;
case RETURN_EMPTY_STRING = 1005;
case RETURN_EMPTY_ARRAY = 1006;
}
18 changes: 8 additions & 10 deletions lib/Exception/InvalidFormatExcption.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@
namespace FriendsOfRedaxo\addon\MediapoolExif\Exception;

use Exception;
use FriendsOfRedaxo\addon\MediapoolExif\Enum\Format;
use Throwable;

/**
* Description of InvalidFormatExcption
*
* @author akrys
*/
class InvalidFormatExcption
extends Exception
class InvalidFormatExcption extends Exception
{
/**
*
* @todo activate type hint if min PHP-Version > 7.4
* @var string
* @var Format
*/
public /* string */ $format;
public Format $format;

/**
* Konstruktor
Expand All @@ -33,20 +31,20 @@ class InvalidFormatExcption
* @param int $code
* @param Throwable $previous
*/
public function __construct(string $format, string $message = "", int $code = 0, Throwable $previous = NULL)
public function __construct(Format $format, string $message = "", int $code = 0, Throwable $previous = NULL)
{
$this->format = $format;
if ($message === '') {
$message = 'Invalid Format: '.$format;
$message = 'Invalid Format: '.$format->value;
}
parent::__construct($message, $code, $previous);
}

/**
* Formatname
* @return string
* @return Format
*/
public function getFormat(): string
public function getFormat(): Format
{
return $this->format;
}
Expand Down
26 changes: 26 additions & 0 deletions lib/Exception/IptcException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
*/
namespace FriendsOfRedaxo\addon\MediapoolExif\Exception;

use Exception;

/**
* Datei für ...
*
* @version 1.0 / 2023-12-09
* @author akrys
*/

/**
* Description of IptcException
*
* @author akrys
*/
class IptcException extends Exception
{

}
7 changes: 2 additions & 5 deletions lib/Exception/NotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
*
* @author akrys
*/
class NotFoundException
extends Exception
class NotFoundException extends Exception
{
/**
*
* @todo activate type hint if min PHP-Version > 7.4
* @var string
*/
public /* string */ $index;
public string $index;

/**
* Konstruktor
Expand Down
29 changes: 6 additions & 23 deletions lib/Exif.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
namespace FriendsOfRedaxo\addon\MediapoolExif;

use FriendsOfRedaxo\addon\MediapoolExif\Enum\MediaFetchMode;
use FriendsOfRedaxo\addon\MediapoolExif\Enum\ReturnMode;
use FriendsOfRedaxo\addon\MediapoolExif\ExifData;
use rex_media;
use rex_sql;
Expand All @@ -19,32 +21,13 @@
*/
class Exif
{
/** @deprecated use FriendsOfRedaxo\addon\MediapoolExi\Enum\Mode::THROW_EXCEPTION */
const MODE_THROW_EXCEPTION = 1000; //should be default
/** @deprecated use FriendsOfRedaxo\addon\MediapoolExi\Enum\Mode::RETURN_NULL */
const MODE_RETURN_NULL = 1001;
/** @deprecated use FriendsOfRedaxo\addon\MediapoolExi\Enum\Mode::RETURN_FALSE */
const MODE_RETURN_FALSE = 1002;
/** @deprecated use FriendsOfRedaxo\addon\MediapoolExi\Enum\Mode::RETURN_ZERO */
const MODE_RETURN_ZERO = 1003;
/** @deprecated use FriendsOfRedaxo\addon\MediapoolExi\Enum\Mode::RETURN_MINUS */
const MODE_RETURN_MINUS = 1004;
/** @deprecated use FriendsOfRedaxo\addon\MediapoolExi\Enum\Mode::RETURN_EMPTY_STRING */
const MODE_RETURN_EMPTY_STRING = 1005;
/** @deprecated use FriendsOfRedaxo\addon\MediapoolExi\Enum\Mode::RETURN_EMPTY_ARRAY */
const MODE_RETURN_EMPTY_ARRAY = 1006;
/** @deprecated use FriendsOfRedaxo\addon\MediapoolExi\Enum\MediaFetchMode::NULL_ONLY */
const GETMEDIA_MODE_NULL_ONLY = 1000;
/** @deprecated use FriendsOfRedaxo\addon\MediapoolExi\Enum\MediaFetchMode::All */
const GETMEDIA_MODE_ALL = 1001;

/**
* Alternative Datenerhebung, analog zu rex_media::get()
*
* @param \FriendsOfRedaxo\addon\MediapoolExif\rex_media $media
* @return ExifData
*/
public static function get(rex_media $media, /*Enum\Mode*/ $mode = Enum\ReturnMode::THROW_EXCEPTION): ExifData
public static function get(rex_media $media, ReturnMode $mode = ReturnMode::THROW_EXCEPTION): ExifData
{
return new ExifData($media, $mode);
}
Expand All @@ -54,15 +37,15 @@ public static function get(rex_media $media, /*Enum\Mode*/ $mode = Enum\ReturnMo
* @param type $mode
* @return array
*/
public static function getMediaToRead(/*Enum\MediaFetchMode*/ $mode = Enum\MediaFetchMode::NULL_ONLY): array
public static function getMediaToRead(MediaFetchMode $mode = MediaFetchMode::NULL_ONLY): array
{
$rexSQL = rex_sql::factory();

switch ($mode) {
case Enum\MediaFetchMode::ALL:
case MediaFetchMode::ALL:
$sql = 'select filename from rex_media';
break;
case Enum\MediaFetchMode::NULL_ONLY:
case MediaFetchMode::NULL_ONLY:
default:
$sql = 'select filename from rex_media where exif is null';
break;
Expand Down
Loading

0 comments on commit 8dda07d

Please sign in to comment.