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

Add autoload paths for app plugins. #64

Merged
merged 4 commits into from
Aug 15, 2023
Merged

Add autoload paths for app plugins. #64

merged 4 commits into from
Aug 15, 2023

Conversation

ADmad
Copy link
Member

@ADmad ADmad commented Apr 15, 2023

This change avoids having to update the app's composer.json to add autoload paths for app plugins under the "plugins" folder.

I have been using a custom composer plugin which does the same for quite a while for my apps.

@ADmad ADmad added this to the 2.0.x milestone Apr 15, 2023
@ADmad
Copy link
Member Author

ADmad commented Apr 15, 2023

After this we can update bake's plugin creating command to run composer dump-autoload instead of modifying the app's composer.json.

@ADmad
Copy link
Member Author

ADmad commented Apr 15, 2023

One can still manually update composer.json and any existing namespace under psr-4 autoload will be left unchanged (as seen for Foo\\ and Foo\Test\\ in the test case).

This change avoids having to update the app's composer.json to add
autoload paths for app plugins under the "plugins" folder.
src/Plugin.php Outdated
Comment on lines 81 to 86
if (!isset($autoload['psr-4'][$pluginNamespace])) {
$autoload['psr-4'][$pluginNamespace] = $path . 'src';
}
if (!isset($devAutoload['psr-4'][$pluginTestNamespace])) {
$devAutoload['psr-4'][$pluginTestNamespace] = $path . 'tests';
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we make sure these directories exist before generating autoloader paths for them? The paths should exist but userland application structures are unpredictable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@markstory
Copy link
Member

This is great 👏 We should announce this on the bakery as it is a good quality of life improvement.

@ADmad
Copy link
Member Author

ADmad commented Apr 16, 2023

This is targeting 2.x. Would have to be backported to 1.x for Cake 4 apps.

@LordSimal
Copy link
Contributor

If we are going to backport it to 1.x I will definitely make a separate video showcasing the differences between the old and the new system. But indeed this is an awesome feature 👍🏻

@LordSimal
Copy link
Contributor

This should be merged before we release Cake5

@markstory markstory merged commit 63ac7e6 into 2.x Aug 15, 2023
4 checks passed
@markstory markstory deleted the 2.0-pre-autoload-dump branch August 15, 2023 16:59
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.

None yet

3 participants