Skip to content

Add Data transformers for download - #10

Open
azathcat wants to merge 1 commit into
mainfrom
feature/transformers
Open

Add Data transformers for download#10
azathcat wants to merge 1 commit into
mainfrom
feature/transformers

Conversation

@azathcat

@azathcat azathcat commented Dec 28, 2020

Copy link
Copy Markdown
Collaborator

Add transformers for specific formats. Here we add just for jed.
closes #2

@azathcat azathcat added the enhancement New feature or request label Dec 28, 2020
@azathcat azathcat self-assigned this Dec 28, 2020
Comment thread lib/Translations.php
Comment on lines +103 to +105
if ( class_exists( $transformer_class ) ) {
$transfomer = new $transformer_class();
return $transfomer->transform( $data, $config );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O $transformer_class que tens agora poderá ser a base, mas seria bom poder receber uma classe de fora para ser mais extensível. Futuro pull request ;)

O resto da lógica para remover complexidade e aumentar o que é testado.

Suggested change
if ( class_exists( $transformer_class ) ) {
$transfomer = new $transformer_class();
return $transfomer->transform( $data, $config );
if ( ! class_exists( $transformer_class ) ) {
return $data;
}
$transfomer = new $transformer_class();
if ( ! $transformer instanceof Transformer ) {
return $data;
}
return $transfomer->transform( $data, $config );

Comment thread lib/Translations.php
JSON_PRETTY_PRINT
);
private function apply_transformer( $data, Project $config ) {
//TODO: receive outside classes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually make sense in this way. What we'll have is a string with the class name for the transformer in the config file. So it'll not come as an argument, but will work mostly as is here.

It's more like this (just a rough example):

$transformer_class = $config->get_tranformer() ? $config->get_tranformer() : __NAMESPACE__ . '\\Transformers\\' . ucfirst( $config->get_format() );

@azathcat

Copy link
Copy Markdown
Collaborator Author

Reminder: careful with the change made in #36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Separate concerns on Translations::download

3 participants