Skip to content

Add autoload paths for app plugins.#64

Merged
markstory merged 4 commits into2.xfrom
2.0-pre-autoload-dump
Aug 15, 2023
Merged

Add autoload paths for app plugins.#64
markstory merged 4 commits into2.xfrom
2.0-pre-autoload-dump

Conversation

@ADmad
Copy link
Copy Markdown
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 ADmad force-pushed the 2.0-pre-autoload-dump branch from 746348b to 20102b9 Compare April 15, 2023 07:30
@ADmad
Copy link
Copy Markdown
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
Copy Markdown
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).

ADmad added 2 commits April 15, 2023 17:51
This change avoids having to update the app's composer.json to add
autoload paths for app plugins under the "plugins" folder.
@ADmad ADmad force-pushed the 2.0-pre-autoload-dump branch from 20102b9 to dc2b5b4 Compare April 15, 2023 12:22
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@ADmad
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

This should be merged before we release Cake5

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.

3 participants