Plugins declare their own namespace, and no longer alias themselves back - #162
Merged
Conversation
Follows FOGProject/fogproject#1535 and FOGProject/fog-plugins#33, which put every plugin class into FOG\Plugins\<Plugin> and taught core to resolve it. ## plugin-development.md Section 7a said "stay in the global namespace", and carried a subsection telling authors that a page, hook, event, report or task in a namespace of their own must end in class_alias(__NAMESPACE__ . '\Foo', 'Foo'). Both are withdrawn. A plugin class declares namespace FOG\Plugins\<Ucfirst-directory>; -- one flat namespace per plugin, whatever subdirectory the file sits in -- and needs no alias, because core now reads each plugin file's own namespace declaration and maps the bare short name onto the FQCN itself. The alias rule was worth deleting rather than restating: a plugin page that got it wrong did not declare the class its filename promised, which is an uncaught TypeError out of FOGPageManager's constructor and a bodyless 500 on every page of the site. New subsections cover what replaced it -- discovery still works by filename, an unconverted plugin keeps loading unchanged, two plugins may now ship a class of the same name, and the one place a bare name still bites (a class name your own code holds in a plain string). The get_class($this) example is now a plugin class, since that advice is true of plugins too. ## 1.6/management/web/reports.md Found while checking that nothing else still recommended an alias, and it was stale for a second reason. The custom-report example declared `namespace FOG;` and `extends ReportManagement`, which resolves FOG\ReportManagement -- a name that stopped existing when core's pages moved into FOG\Pages, and which the autoloader now refuses outright rather than bridging. Copying the example gave a fatal, not a report. It is a global-namespace file extending \FOG\Pages\ReportManagement now, with no class_alias, plus a note on where a report shipped inside a plugin differs. Note translations/fr/development/plugin-development.md is now stale; left untouched rather than machine-translated. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Documentation for FOGProject/fogproject#1535 + FOGProject/fog-plugins#33, which put every plugin class into
FOG\Plugins\<Plugin>and taught core to resolve it. Merge after those.development/plugin-development.md§7a said "stay in the global namespace", and carried a subsection telling authors that a page, hook, event, report or task in a namespace of their own must end in
class_alias(__NAMESPACE__ . '\Foo', 'Foo'). Both are withdrawn.A plugin class declares
namespace FOG\Plugins\<Ucfirst-directory>;— one flat namespace per plugin, whatever subdirectory the file sits in — and needs no alias, because core reads each plugin file's ownnamespacedeclaration and maps the bare short name onto the FQCN itself.The alias rule was worth deleting rather than restating more clearly: a plugin page that got it wrong did not declare the class its filename promised, which is an uncaught
TypeErrorout ofFOGPageManager's constructor and a bodyless 500 on every page of the site, recoverable only from a shell.New subsections cover what replaced it:
.page.php/.hook.phpsuffixes are how a file gets found, so nothing moved and nothing was renamed. This is namespacing, not a PSR-4 move.The
get_class($this)example is now a plugin class, since that advice is true of plugins too.1.6/management/web/reports.md— found on the way, and separately brokenChecking that nothing else still recommended an alias turned up the custom-report example, stale for a second reason:
Unqualified inside
namespace FOG;that resolvesFOG\ReportManagement— a name that stopped existing when core's pages moved intoFOG\Pages, and which the autoloader now refuses outright rather than bridging (it logs the correct FQCN and returns). Copying the example gave a fatal, not a report.It is now a global-namespace file extending
\FOG\Pages\ReportManagement, with noclass_alias, plus a note on how a report shipped inside a plugin differs.Not done
translations/fr/development/plugin-development.mdis now stale. Left untouched rather than machine-translated.