Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Improved FileResource and DirectoryResource #17598

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 5 commits into from

Conversation

javiereguiluz
Copy link
Member

Q A
Bug fix? no
New feature? yes
BC breaks? yes?
Deprecations? no
Tests pass? yes
Fixed tickets #15946
License MIT
Doc PR -

*/
public function __construct($resource)
{
$this->resource = realpath($resource);

if (!file_exists($this->resource)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

realpath already returns false if it doesn't exist. so this is useless.

@Tobion
Copy link
Contributor

Tobion commented Jan 29, 2016

  1. phpdoc of FiileResource::getResource is not correct anymore
  2. string cast in __toString doesnt make sense anymore
  3. the check in isFresh false === $this->resource does not make sense

Status: Needs Work

@javiereguiluz
Copy link
Member Author

@Tobion I've fixed everything you said. Thanks for the review!

*/
public function __construct($resource)
{
$this->resource = realpath($resource);

if (false === $this->resource) {
throw new \InvalidArgumentException(sprintf('The "%s" file does not exist.', $resource));
Copy link
Contributor

Choose a reason for hiding this comment

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

usually you write it the other way round: The file "%s" does not exist. (same for directory)

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right. Changed. Thanks.

@Tobion
Copy link
Contributor

Tobion commented Jan 29, 2016

FileResource::isFresh is not safe against race conditions (when it's deleted between file_exists and filemtime). So it probably need error supression instead with @filemtime.
Similar problem in DirectoryResource::isFresh.

@javiereguiluz
Copy link
Member Author

Should I replace this:

public function isFresh($timestamp)
{
    if (!file_exists($this->resource)) {
        return false;
    }

    return filemtime($this->resource) <= $timestamp;
}

by this?

public function isFresh($timestamp)
{
    return file_exists($this->resource) && filemtime($this->resource) <= $timestamp;
}

@javiereguiluz
Copy link
Member Author

This PR just needs a final boost to finish it. Should I do the change mentioned in my previous comment? Thanks!

@jakzal
Copy link
Contributor

jakzal commented Feb 3, 2016

@javiereguiluz I say go for it! Personally, I find the one liner more readable.

@javiereguiluz
Copy link
Member Author

@jakzal OK. Changed. Thanks.

}

return filemtime($this->resource) <= $timestamp;
return file_exists($this->resource) && filemtime($this->resource) <= $timestamp;
Copy link
Member

Choose a reason for hiding this comment

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

I think @Tobion meant: return file_exists($this->resource) && @filemtime($this->resource) <= $timestamp;.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. Changed.

@fabpot
Copy link
Member

fabpot commented Feb 3, 2016

Thank you @javiereguiluz.

@fabpot fabpot closed this in ba25521 Feb 3, 2016
}

return filemtime($this->resource) <= $timestamp;
return file_exists($this->resource) && @filemtime($this->resource) <= $timestamp;
Copy link
Contributor

Choose a reason for hiding this comment

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

filemtime returns false on error which means isFresh evaluetes to true in this case (false < timestamp) which is wrong.

nicolas-grekas added a commit that referenced this pull request Feb 4, 2016
…rce objects (xabbuh)

This PR was merged into the 2.3 branch.

Discussion
----------

[DependencyInjection][Routing] add files used in FileResource objects

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17598 (comment)
| License       | MIT
| Doc PR        |

Starting with Symfony 3.1, the constructor of the `FileResource` class
will throw an exception when the passed file does not exist.

Commits
-------

4f865c7 add files used in FileResource objects
nicolas-grekas added a commit that referenced this pull request Feb 4, 2016
This PR was merged into the 2.8 branch.

Discussion
----------

[Routing] add files used in FileResource objects

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17598 (comment)
| License       | MIT
| Doc PR        |

Starting with Symfony 3.1, the constructor of the `FileResource` class
will throw an exception when the passed file does not exist.

Commits
-------

73afd0f add files used in FileResource objects
symfony-splitter pushed a commit to symfony/routing that referenced this pull request Feb 4, 2016
This PR was merged into the 2.8 branch.

Discussion
----------

[Routing] add files used in FileResource objects

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#17598 (comment)
| License       | MIT
| Doc PR        |

Starting with Symfony 3.1, the constructor of the `FileResource` class
will throw an exception when the passed file does not exist.

Commits
-------

73afd0f add files used in FileResource objects
fabpot added a commit that referenced this pull request May 23, 2016
This PR was merged into the 3.1 branch.

Discussion
----------

[Config] Allow schemed paths in FileResource

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17598
| License       | MIT
| Doc PR        | -

This is a small new feature fixing a BC break that has been introduced in #17598 on 3.1.
It happens that 3.1 is breaking a `phar` app on our side where we end up doing something like `new FileResource('phar://...')`.

Ping @xabbuh and @javiereguiluz esp.

Commits
-------

c73f34d [Config] Allow schemed path in FileResource
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.

7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.