-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add Event for Glossary detection
- Loading branch information
Showing
5 changed files
with
108 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WebVision\Deepltranslate\Core\Domain\Dto; | ||
|
||
use WebVision\Deepltranslate\Core\Exception\MissingParameterException; | ||
|
||
final class CurrentPage | ||
{ | ||
public function __construct( | ||
private readonly int $uid, | ||
private readonly string $title | ||
) { | ||
} | ||
|
||
/** | ||
* @throws MissingParameterException | ||
*/ | ||
public static function fromArray(array $record): self | ||
{ | ||
if (!array_key_exists('uid', $record) || !array_key_exists('title', $record)) { | ||
throw new MissingParameterException( | ||
'Missing parameters in creating CurrentPage Domain Transfer Object', | ||
1734445433 | ||
); | ||
} | ||
return new self((int)$record['uid'], $record['title']); | ||
} | ||
|
||
public function getUid(): int | ||
{ | ||
return $this->uid; | ||
} | ||
|
||
public function getTitle(): string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WebVision\Deepltranslate\Core\Event; | ||
|
||
use WebVision\Deepltranslate\Core\Domain\Dto\CurrentPage; | ||
|
||
final class GlossaryKeyEvent | ||
{ | ||
private ?string $glossaryId = null; | ||
|
||
public function __construct( | ||
private readonly string $sourceLanguage, | ||
private readonly string $targetLanguage, | ||
private readonly ?CurrentPage $currentPage | ||
) { | ||
} | ||
|
||
public function setGlossaryId(string $glossaryId): void | ||
{ | ||
$this->glossaryId = $glossaryId; | ||
} | ||
|
||
public function getGlossaryId(): ?string | ||
{ | ||
return $this->glossaryId; | ||
} | ||
|
||
public function getSourceLanguage(): string | ||
{ | ||
return $this->sourceLanguage; | ||
} | ||
|
||
public function getTargetLanguage(): string | ||
{ | ||
return $this->targetLanguage; | ||
} | ||
|
||
public function getCurrentPage(): ?CurrentPage | ||
{ | ||
return $this->currentPage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WebVision\Deepltranslate\Core\Exception; | ||
|
||
final class MissingParameterException extends \Exception {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters