Power-Based Class Overriding & Source Injection #1012
Llewellynvdm
started this conversation in
Documentation
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
One of the most powerful additions is the ability to use Powers to override or inject PHP classes directly into the generated
src/folders of Components, Modules, and Plugins.This is not guesswork, magic, or a loose convention — it is fully deterministic, namespace-driven, and designed to be portable across projects.
This section explains exactly how it works, with concrete examples.
Core Concept: Namespace = Destination
JCB determines where a Power class is placed (and whether it overrides an existing generated class) purely from its namespace.
There are two key ideas:
If a Power resolves to the same namespace + class name as a generated class, it overrides it.
If it resolves to a new namespace + class name, it adds a new file.
Dynamic Placeholders (Critical for Reusability)
JCB supports dynamic placeholders inside Power namespaces so that the same Power can be reused across multiple projects without modification.
Available placeholders
[[[NamespacePrefix]]]→ Dynamically replaced with the project’s namespace prefix
[[[ComponentNamespace]]]→ Dynamically replaced with the project’s component namespace
[[[Componment]]]→ Dynamically replaced with the project’s component name
These placeholders allow a Power to adapt itself automatically when used in different components, modules, or projects.
Component Examples
Override an existing generated Component class
To override the generated file:
Use this Power namespace:
What happens:
ComponentbuilderComponent.phpfileThis is a true override, not a hook or decoration.
Add a new file to the Component Administrator src area
Resulting file path:
No generated class is replaced — this file is added to the component admin
src/tree.Add a new file to the Component Site src area
Resulting file path:
Again, this is a clean addition, not an override.
Module Examples
Override a Module Dispatcher
To override the generated module file:
Use this Power namespace:
Where:
CPanelRedirectmust be your module nameEffect:
Add a file to the Module Administrator src area
Result:
Add a file to the Module Site src area
Result:
Plugin Examples
Override an existing Plugin class
To override the generated plugin file:
Use this Power namespace:
Where:
ComponentbuilderPowersAutoloaderCompileris the plugin nameOutcome:
Add a new file to the Plugin src area
Result:
Dot Notation Explained (Why It Works)
JCB uses dot notation inside the namespace to determine:
Example:
Becomes:
This applies consistently across Components, Modules, and Plugins.
Using the Class in Your Code (JPK Integration)
Once the Power is placed into the correct
src/location, you can:JCB automatically ensures the class is available and loaded.
Important Trade-Offs (By Design)
This feature intentionally gives you full control, which means:
If you override a generated class, you own it
JCB will not regenerate that class unless you remove the Power
This is ideal for:
It is optional, explicit, and never forced.
Why This Matters
This turns Powers into:
You can now:
Beta Was this translation helpful? Give feedback.
All reactions