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

Refactor Rename #222

Draft
wants to merge 1 commit into
base: 3.0.x
Choose a base branch
from
Draft

Refactor Rename #222

wants to merge 1 commit into from

Conversation

ramchale
Copy link
Contributor

@ramchale ramchale commented Jan 8, 2025

Q A
Documentation no
Bugfix no
BC Break yes
New Feature no
RFC no
QA no

Description

Refactoring for #177

I had a couple of questions around the intent for v3;

  • I'm assuming removal of getFile and setFile, but wanted to check if we're also removing addFile
  • Currently the input for addFile can be a string, or array of target, etc, or an array of arrays of target, etc. Which of these do we want to support going forward?

Signed-off-by: ramchale <[email protected]>
@gsteel
Copy link
Member

gsteel commented Jan 8, 2025

I'm not entirely sure because I haven't had a decent look at it myself, but:

  • Make use of Laminas\Filter\File\FileInformation value object which exists to handle the 3 possible argument types of string|PHP $_FILES|PSRUpload
  • I think ideally, expect a single input, i.e. 1 path, or 1 PSR Upload or 1 PHP Upload and return a string representing the new, modified file path (Or un-filtered input)
  • We may have revise, that, i.e. we might need to accept multiple inputs for PSR/$_FILES but I'd rather avoid that if possible because we then have awkward return type expectations, IMO, successful filtering should === (string) $newFilePath
  • If there is a public method other than filter or __invoke, kill it with 🔥

My reasoning here is that we shouldn't need to worry too much about compat with input filter and form, because they are next in line for major release, and, if you want to deal with multiple uploads, then, from input filters perspective, we should be looking at an 'ArrayInput' wrapping n 'FileInput's rather than all this type juggling.

Options:

  • I think target should exclusively mean "Target Directory"
  • source does not make sense and I think it should be removed - the "source" is the filter input
  • overwrite and randomize seem sensible enough

Further reference:

cc @froschdesign @weierophinney

@froschdesign
Copy link
Member

froschdesign commented Jan 8, 2025

@gsteel

  • source does not make sense and I think it should be removed - the "source" is the filter input

The source option is relevant if several files are to be filtered, see the example in the documentation:

$filter = new \Laminas\Filter\File\Rename([
    [
        'source'    => 'fileA.txt'
        'target'    => '/dest1/newfileA.txt',
        'overwrite' => true,
    ],
    [
        'source'    => 'fileB.txt'
        'target'    => '/dest2/newfileB.txt',
        'randomize' => true,
    ],
]);

But I would follow your idea and the source option is no longer needed:

I think ideally, expect a single input, i.e. 1 path, or 1 PSR Upload or 1 PHP Upload and return a string representing the new, modified file path (Or un-filtered input)

I also think that is the right way to go:

if you want to deal with multiple uploads, then, from input filters perspective, we should be looking at an 'ArrayInput' wrapping n 'FileInput's rather than all this type juggling.


If several values are to be filtered, a decorator can still be created for this purpose.

@gsteel gsteel mentioned this pull request Jan 8, 2025
54 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants