Skip to content
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

56 autoloading enhancements #58

Merged
merged 14 commits into from
Apr 17, 2024
Merged

56 autoloading enhancements #58

merged 14 commits into from
Apr 17, 2024

Conversation

JasperTey
Copy link
Member

@JasperTey JasperTey commented Apr 15, 2024

Added

  • Ability to ignore folders during autoloading via config(ddd.autoload_ignore), or register a custom filter callback via DDD::filterAutoloadPathsUsing(callable $filter).

Changed

  • Internal: Domain cache is no longer quietly cleared on laravel's cache:clearing event, so that ddd:cache yields consistent results no matter which order it runs in production (before or after cache:clear or optimize:clear commands).

Ignoring Paths During Autoloading

To specify folders or paths that should be skipped during autoloading discovery, add them to the ddd.autoload_ignore configuration option. By default, the Tests and Migrations folders are ignored.

'autoload_ignore' => [
    'Tests',
    'Database/Migrations',
],

Paths specified here are relative to the root of each domain. e.g., src/Domain/Invoicing/{path-to-ignore}. If more advanced filtering is needed, a callback can be registered using DDD::filterAutoloadPathsUsing(callback $filter) in your AppServiceProvider's boot method:

use Lunarstorm\LaravelDDD\Facades\DDD;
use Symfony\Component\Finder\SplFileInfo;

DDD::filterAutoloadPathsUsing(function (SplFileInfo $file) {
    if (basename($file->getRelativePathname()) === 'functions.php') {
        return false;
    }
});

@JasperTey JasperTey linked an issue Apr 15, 2024 that may be closed by this pull request
@JasperTey
Copy link
Member Author

Draft PR, would be helpful if you could test it out in your project, @pelmered.

Update the composer.json require to:

"lunarstorm/laravel-ddd": "dev-56-autoloading-enhancements"

And composer update --no-dev

Then ensure config file is updated to contain an autoload_ignore configuration. (details above)

Custom filter callback via DDD::filterAutoloadPathsUsing() is available too.

When I tested all of this against your cloned laravel-test-ddd repo, this PR did appear to resolve the migrations issue too. I tried placing non-psr compliant migration files into the domain folder under src/Domain/Test/Database/Migrations, and both ddd:cache and composer didn't raise any errors. So the issues I was having with composer errors must've been only under the package testing environment. In a real application it seems to be fine.

@pelmered
Copy link
Contributor

Thanks a lot @JasperTey!

I will try this out now.

@pelmered
Copy link
Contributor

It seems to work well. I had some other issues related to the autoload in our CI pipeline, but it turned out that I could fix that as well with theses changes.
Good work! Full approval from me!

@JasperTey JasperTey marked this pull request as ready for review April 17, 2024 12:02
@JasperTey JasperTey merged commit 7f9edea into main Apr 17, 2024
21 checks passed
@JasperTey JasperTey deleted the 56-autoloading-enhancements branch April 17, 2024 12:03
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.

Autoloading issues
2 participants