Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to filter yaml keys #35

Conversation

matthiashamacher
Copy link
Contributor

No description provided.

Signed-off-by: Matthias Hamacher <m.hamacher@basecom.de>
@matthiashamacher
Copy link
Contributor Author

We just now noticed that the fix:structure Command seems to be removing the filtered entries from the result file. I will have a look how we can fix that, but so long this should not be merged and released.

{
$result = [];

foreach ($array as $key => $value) {
if ($filter instanceof Filter && $filter->isKeyAllowed($key) === false) {
continue;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't continue here but save the filtered keys into an additional array, we can remove them during loading and merging those two array together during saving/writing.

@boxblinkracer Would that be a feasible solution for the problem that the filtered keys are remove with the fix:structure command?

Copy link
Owner

Choose a reason for hiding this comment

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

hi
yes thats absolutely fine, a really good idea
so is that now already working, can i merge it like this @matthiashamacher ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No not right now. Wanted your input first so I haven't added it. Will add it later today and ping you so you can merge it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Finally found to time to finalize this pr. Was a little bit more complicated than I thought but I think its an ok solution @boxblinkracer Please have a look.

Copy link
Owner

Choose a reason for hiding this comment

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

hi @matthiashamacher
awesome thank you, ill check it out later or this weekend :)
thanks for your work on that, means a lot

Signed-off-by: Matthias Hamacher <m.hamacher@basecom.de>
$filteredTranslations = [];

foreach ($array as $key => $value) {
if ($filter->isKeyAllowed($key, true) === true) {
Copy link
Owner

Choose a reason for hiding this comment

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

the only thing that i dont really get is the partial allowing?
why do we have that?
can you also explain that in a comment.
if i want to filter an array, i dont see a point where i would need partial filtering

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before I add the comment I explain it here, maybe there is a better way for the whole solution.

Background is that filtering during the first run through of flattening the array was no good solution in my opinion. During implementation there were too many changes needed to be done to save the filtered results. Therefore I moved it to this new function. As this runs after the array is flattened we have an array like this:

$array = [
    'app.name' => 'test',
    'app.description' => 'test',
];

If we now want to filter out description, we cannot filter by an exact match as the string would is app.description therefore we need the partial match.

@matthiashamacher matthiashamacher closed this by deleting the head repository Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants