Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Finder] adds adapter selection/unselection capabilities #7212

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

Conversation

jfsimon
Copy link
Contributor

@jfsimon jfsimon commented Feb 28, 2013

As we have many issues with the native finder adapter, it would be good to:

  • permit selection of a particular adapter which will be choosed over the others until its unselection
  • permit unselection of adapters to get the finder select trhe best on (by priority)
  • have PhpAdapter selected by default

This PR adds 2 methods to the Finder:

  • setAdapter($adapter): selects an adapter by its name
  • useBestAdapter(): tells the finder to select best adapter by their priority
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes

*/
public function setAdapter(Adapter\AdapterInterface $adapter, $priority = 0)
{
if (!isset($this->adapters[$adapter->getName()])) {
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 we need two methods here: one to add/register a new adapter (already covered by the addAdapter() method) and one to select the adapter to be used by default (the name can be setAdapter() as in this PR but it should take the adapter name as its only argument).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabpot yep, done.

public function setAdapter($name)
{
if (!isset($this->adapters[$name])) {
throw new \InvalidArgumentException(sprintf('There is no registered adapter with "%s" name.', $name));
Copy link
Member

Choose a reason for hiding this comment

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

Adapter "%s" does not exist..

@jfsimon
Copy link
Contributor Author

jfsimon commented Feb 28, 2013

@fabpot I just applied all your good advices, there was no bad one :)

fabpot added a commit that referenced this pull request Feb 28, 2013
This PR was squashed before being merged into the 2.2 branch (closes #7212).

Commits
-------

f40adbc [Finder] adds adapter selection/unselection capabilities

Discussion
----------

[Finder] adds adapter selection/unselection capabilities

As we have many issues with the native finder adapter, it would be good to:
*  permit selection of a particular adapter which will be choosed over the others until its unselection
*  permit unselection of adapters to get the finder select trhe best on (by priority)
*  have `PhpAdapter` selected by default

This PR adds 2 methods to the `Finder`:
*  `setAdapter($adapter)`: selects an adapter by its name
*  `useBestAdapter()`: tells the finder to select best adapter by their priority

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes

---------------------------------------------------------------------------

by jfsimon at 2013-02-28T14:05:25Z

@fabpot I just applied all your good advices, there was no bad one :)
@fabpot fabpot closed this Feb 28, 2013
*
* @return Finder The current Finder instance
*/
public function setAdapter($name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have something like getSupportedAdapeters ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

"Supported" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adapters support is determined in searchInDirectory.
There is no way to get them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Adapters support is determined in searchInDirectory.

true but only when canBeUsed()returns true, right ?

Copy link
Contributor

Choose a reason for hiding this comment

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

(I am not sure if my suggestion makes sense, just asking)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think it would be useful?
I can't see any use case.

Copy link
Contributor

Choose a reason for hiding this comment

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

don't know... I have to think more about it.

What triggers the idea is setAdapter (ie you would not want to set something that is not supported)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, this is not stupid...
I'll open an RFC tomorrow, could you keep your ideas in mind and feed comments with them?

Copy link
Contributor

Choose a reason for hiding this comment

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

sure, please also link this comment. thanks.

chat to you tomorrow.

On 02/28/2013 05:49 PM, Jean-François Simon wrote:

In src/Symfony/Component/Finder/Finder.php:

  • {
  •    $this->resetAdapterSelection();
    
  •    return $this->sortAdapters();
    
  • }
  • /**
  • \* Selects the adapter to use.
    
  • *
    
  • \* @param string $name
    
  • *
    
  • \* @throws \InvalidArgumentException
    
  • *
    
  • \* @return Finder The current Finder instance
    
  • */
    
  • public function setAdapter($name)

Hmm, this is not stupid...
I'll open an RFC tomorrow, could you keep your ideas in mind and feed
comments with them?


Reply to this email directly or view it on GitHub
https://github.com/symfony/symfony/pull/7212/files#r3191594.

@Seldaek
Copy link
Member

Seldaek commented Aug 12, 2013

I just had to disable useBestAdapter() in composer since it was causing issues on solaris (composer/composer#2168). Is there no way to check if find is the proper gnu find before enabling this adapter?

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.

4 participants