Skip to content

Use getPathname() instead of string casting to get BinaryFileReponse file path #11837

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

Closed
wants to merge 6 commits into from

Conversation

nervo
Copy link
Contributor

@nervo nervo commented Sep 3, 2014

According to the code, should be "File" instead of "\SplFileInfo"

According to the code, should be "File" instead of "\SplFileInfo"
@stof
Copy link
Member

stof commented Sep 3, 2014

Removing \SplFileInfo is wrong. It is accepted too. And adding File is not needed as it is a child class of \SplFileInfo

@nervo
Copy link
Contributor Author

nervo commented Sep 3, 2014

Ok, let's try to disambiguate the situation.
I was trying to use a \SplFileObject as $file parameter. \SplFileObject extends \SplFileInfo, but don't stringify the same.
\SplFileObject::__toString() is an alias of ::current and returns the current line of file (and returns an array if csv flag is set)(true story)
\SplFileInfo::__toString() returns the pathname, which is acceptable as the File class constructor.

I think, we should check the instance of file, and in case of \SplFileInfo, use the getPathName() method instead of string casting

@stof
Copy link
Member

stof commented Sep 3, 2014

then we should fix the way we get the path name for SplFileInfo to support the SplFileObject child class. This is actually a bug.

Btw, the fact that SplFileObject::__toString() can return an array should be reported as a PHP bug IMO

@nervo nervo changed the title Fix phpdoc file param in BinaryFileResponse.php Use getPathname() instead of string casting to get BinaryFileReponse file path Sep 4, 2014
@nervo
Copy link
Contributor Author

nervo commented Sep 4, 2014

Ok, i've updated the pr.
Could we say i have just been half-stoffed ?

@stof
Copy link
Member

stof commented Sep 4, 2014

Please add a test using SplFileObject to avoid regressions

@nervo
Copy link
Contributor Author

nervo commented Sep 9, 2014

Done :)

@fabpot
Copy link
Member

fabpot commented Sep 10, 2014

👍


$response = new BinaryFileResponse($file);

$this->assertEquals($response->getfile()->getPathname(), $filePath);
Copy link
Member

Choose a reason for hiding this comment

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

This test will fail on Windows because of directory separator mismatch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stof well, all of the BinaryFileResponseTest tests are based on such paths...

Copy link
Member

Choose a reason for hiding this comment

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

nope. None of the other tests is doing an assertion on $response->getfile()->getPathname()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, sorry, i didn't get it.
I will fix that.

Copy link
Member

Choose a reason for hiding this comment

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

By the way, the "f" in getFile() should be upper-cased.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooops, nice catch !

@nervo
Copy link
Contributor Author

nervo commented Sep 10, 2014

Ok, using realpath should do the trick.

@fabpot
Copy link
Member

fabpot commented Sep 17, 2014

Thank you @nervo.

fabpot added a commit that referenced this pull request Sep 17, 2014
…ileReponse file path (nervo)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11837).

Discussion
----------

Use getPathname() instead of string casting to get BinaryFileReponse file path

According to the code, should be "File" instead of "\SplFileInfo"

Commits
-------

e1eb788 Use getPathname() instead of string casting to get BinaryFileReponse file path
@fabpot fabpot closed this Sep 17, 2014
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.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy