Skip to content

[DI] FileLoaders: Allow to explicit type to load #20611

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

Merged
merged 1 commit into from
Jan 10, 2017
Merged

[DI] FileLoaders: Allow to explicit type to load #20611

merged 1 commit into from
Jan 10, 2017

Conversation

ogizanagi
Copy link
Contributor

@ogizanagi ogizanagi commented Nov 23, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #20308
License MIT
Doc PR Not yet

(fabbot will scream out regarding the PR fixtures)

Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

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

👍

return false;
}

if (null !== $type && 'ini' === $type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would make these the final returns, ie. return 'ini' === $type;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed it's better 👍 Thanks.

@chalasr
Copy link
Member

chalasr commented Nov 23, 2016

👍

return true;
}

return null !== $type && 'ini' === $type;
Copy link
Member

Choose a reason for hiding this comment

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

return 'ini' === $type; should be enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Forgot to update after #20611 (comment)... Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we check type first? If I set this option explicitly, I expect it to have top priority:

public function supports($resource, $type = null)
{
    if (!is_string($resource)) {
        return false;
    }

    return 'ini' === $type || 'ini' === pathinfo($resource, PATHINFO_EXTENSION);
}

Copy link
Member

Choose a reason for hiding this comment

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

@javiereguiluz the extension is checked only when the type is null. So there is no question of priority

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the type will have priority if explicitly provided with current implementation, as the above condition has a null === $type check.

The difference with your snippet is that the loader won't return true in case the type was explicitly provided, but not ini and the extension is ini (another loader should try)

Copy link
Member

@javiereguiluz javiereguiluz Jan 10, 2017

Choose a reason for hiding this comment

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

the loader won't return true in case the type was explicitly provided, but not ini and the extension is ini (another loader should try)

@ogizanagi in that case, this code will be: ...
Maybe I'm missing something here.

updated: I see my mistake now. Thanks!

@stof maybe "priority" is not the best word, but the new behavior is: "do whatever "type" tells you ... if it doesn't tell you anything, fall back to the file extension".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I meant is calling:

  1. supports('services.ini, 'ini') should return true
  2. supports('services.foo, 'ini') should return true
  3. supports('services.ini, 'yaml') should return false

The third case will be erroneous with your suggestion.

@stof
Copy link
Member

stof commented Nov 24, 2016

This is a new feature IMO, not a bugfix (we never said that type: yml was intended to trigger the YAML loader, so we cannot consider this behavior as buggy)

@xabbuh
Copy link
Member

xabbuh commented Nov 24, 2016

@stof The PR is already labelled as a feature and is based on the master branch. :)

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
return true;
}

return null !== $type && 'php' === $type;
Copy link
Member

Choose a reason for hiding this comment

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

null !== $type should be removed in all loaders. It is useless as the condition 'php' === $type already ensures is is not null

Copy link
Contributor Author

@ogizanagi ogizanagi Jan 10, 2017

Choose a reason for hiding this comment

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

Don't know what happened here, I'm pretty sure I fixed this a long time ago... Thanks.

@javiereguiluz
Copy link
Member

👍

Status: reviewed

@fabpot
Copy link
Member

fabpot commented Jan 10, 2017

Thank you @ogizanagi.

@fabpot fabpot merged commit 6b660c2 into symfony:master Jan 10, 2017
fabpot added a commit that referenced this pull request Jan 10, 2017
…anagi)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] FileLoaders: Allow to explicit type to load

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

(fabbot will scream out regarding the PR fixtures)

Commits
-------

6b660c2 [DI] FileLoaders: Allow to explicit type to load
@ogizanagi ogizanagi deleted the feature/dic/file_loaders_type branch January 10, 2017 17:56
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@fabpot fabpot mentioned this pull request May 1, 2017
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.

9 participants