Skip to content

Plugins declare their own namespace, and no longer alias themselves back - #162

Merged
mastacontrola merged 1 commit into
masterfrom
plugin-namespace-docs
Aug 31, 2026
Merged

Plugins declare their own namespace, and no longer alias themselves back#162
mastacontrola merged 1 commit into
masterfrom
plugin-namespace-docs

Conversation

@mastacontrola

Copy link
Copy Markdown
Member

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 own namespace declaration 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 TypeError out of FOGPageManager's constructor and a bodyless 500 on every page of the site, recoverable only from a shell.

New subsections cover what replaced it:

  • Discovery still works by filename — the .page.php / .hook.php suffixes are how a file gets found, so nothing moved and nothing was renamed. This is namespacing, not a PSR-4 move.
  • Backwards compatible — a plugin with no namespace keeps loading unchanged. Third-party authors need do nothing.
  • Two plugins, one class name, no collision — the new guarantee.
  • 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 on the way, and separately broken

Checking that nothing else still recommended an alias turned up the custom-report example, stale for a second reason:

namespace FOG;
class Example_Report extends ReportManagement

Unqualified inside namespace FOG; that 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 (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 no class_alias, plus a note on how a report shipped inside a plugin differs.

Not done

translations/fr/development/plugin-development.md is now stale. Left untouched rather than machine-translated.

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>
@mastacontrola
mastacontrola merged commit a5fd432 into master Aug 31, 2026
@mastacontrola
mastacontrola deleted the plugin-namespace-docs branch August 31, 2026 13:35
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.

1 participant