laravel / pennant

A simple, lightweight library for managing feature flags.
https://laravel.com/docs/pennant
MIT License
474 stars 48 forks source link

[1.x] Safely return early if there is nothing to discover() #94

Closed inmanturbo closed 6 months ago

inmanturbo commented 6 months ago

Otherwise Feature::discover() will throw Symfony\ Component\Finder\Exception\ DirectoryNotFoundException if no class based features have been added yet, or if all features have been removed.

    public function discover($namespace = 'App\\Features', $path = null)
    {

+        if (!$path && !is_dir(base_path('app/Features'))) {
+           return;
+        }

Prevents running into apps with a app/Features/.gitkeep. ( I actually caught myself doing this rather than checking for the directory before running Feature::discover() in a service provider)

Note: Sometimes you need to run Feature::discover() not know whether there will be any, especially if more than one developer is working on the app and whatever you are doing depends on a feature being defined (but you may not be the one to define or implement it).

github-actions[bot] commented 6 months ago

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

inmanturbo commented 6 months ago

I'm closing this because unfortunately it could break existing applications if they are relying on this to throw.

I recommend try{} catch {} as a reasonable alternative.