d7-loader
Skill4 starsChanged 4 months agoMITView on GitHub
Include 1C-Bitrix modules and autoload their classes safely with the D7 \Bitrix\Main\Loader — includeModule, dependency checks, fail-fast on missing modules, and legacy CModule::IncludeModule compatibility. Use when the user is wiring up autoloading for a module's namespaced classes or a custom module's classes — resolving a "class not found" that stems from a module not being loaded, or registering a class autoload map; the user needs to include a Bitrix module — `Loader::includeModule('iblock')` (D7) or the legacy `CModule::IncludeModule()` — before touching that module's classes, ORM, or functions; the user needs to know if a module is present before using it — checking availability, guarding an optional feature, or branching on whether `sale`, `catalog`, or a custom module is installed. Keywords: bitrix, loader, module, includemodule, dependencies, autoload, d7, legacy, битрикс, модуль, загрузчик.
In this repository119 other files it gives its agents.
- strategy-bitrix-d7-incrementalSkill
- strategy-explicit-over-magicSkill
- strategy-framework-conventionsSkill
- strategy-legacy-safe-editsSkill
- strategy-minimal-diffSkill
- strategy-no-untested-refactorSkill
- strategy-preserve-public-apiSkill
- strategy-readonly-immutabilitySkill
- strategy-security-firstSkill
- strategy-test-drivenSkill
- openapiSkill
- paginationSkill
- rest-designSkill
- versioningSkill
- cqrsSkill
- dependency-inversionSkill
- hexagonalSkill
- repository-patternSkill
- service-layerSkill
- bitrixSkill
- findings-reportSkill
- laravelSkill
- performanceSkill
- phpSkill
- project-analysisSkill
- refactoringSkill
- roi-prioritizationSkill
- securitySkill
- stack-detectionSkill
- cache-layersSkill
- component-engineSkill
- d7-eventsSkill
- d7-orm-queriesSkill
- iblock-elementsSkill
- kernel-main-moduleSkill
- localizationSkill
- controllersSkill
- ormSkill
- validationSkill
- controllersSkill
- query-builderSkill
- routingSkill
- autoload-psr4Skill
- dependency-managementSkill
- scriptsSkill
- connection-poolingSkill
- mysql-indexingSkill
- redisSkill
- transactionsSkill
- ci-github-actionsSkill
- deployment-strategiesSkill
- docker-phpSkill
- env-configSkill
- associationsSkill
- entities-mappingSkill
- orm-basicsSkill
- entity-apiSkill
- module-developmentSkill
- routing-controllersSkill
- formsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 74
Do not use this skill to bootstrap the kernel, read the Request, or resolve Application/Context services — that is the kernel (main module) …
- Very specific: line 77
Do not use this skill on a non-Bitrix PHP app (plain PHP, Laravel, Symfony).
- Very specific: line 93
Only after the guard passes, reference the module's namespaced classes (for example \Bitrix\Iblock\ElementTable).
- Very specific: line 101
When a module is required for the code to work at all, fail fast — throw a \Bitrix\Main\LoaderException or a \RuntimeException immediately …
- Distinctive: line 107
When a module powers only an optional feature, branch on the false return and degrade gracefully — hide the feature or use a fallback — …
- Distinctive: line 146
Not applicable — no I/O, auth, or untrusted input.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- generated: do not edit — source: knowledge/atoms/bitrix/d7-loader/ --><!-- schema: atomVersion=3 skillVersion=2 graphVersion=1 --><!-- compile: @php-skills/compiler v1.0.0 (deterministic build) -->Bitrix D7 Loader
When to use
- The user is wiring up autoloading for a module's namespaced classes or a custom module's classes — resolving a "class not found" that stems from a module not being loaded, or registering a class autoload map.
- The user needs to include a Bitrix module —
Loader::includeModule('iblock')(D7) or the legacyCModule::IncludeModule()— before touching that module's classes, ORM, or functions. - The user needs to know if a module is present before using it — checking
availability, guarding an optional feature, or branching on whether
sale,catalog, or a custom module is installed.
When NOT to use
- Do not use this skill to bootstrap the kernel, read the Request, or resolve Application/Context services — that is the kernel (main module) concern, not the Loader's job of including modules.
- Do not use this skill on a non-Bitrix PHP app (plain PHP, Laravel, Symfony);
\Bitrix\Main\Loaderand the module system do not exist outside 1C-Bitrix.
Core guidance
- Prefer the D7 Loader for new code — In new code use
\Bitrix\Main\Loader::includeModule()rather than the legacyCModule::IncludeModule(); both include the module, but the D7 Loader is the namespaced, current API.
Quick recipe
- At the top of the entry point call
if (!\Bitrix\Main\Loader::includeModule('iblock')) { ... }and handle the false branch before any module class is referenced. (verify: A missingiblockmodule reaches the false branch instead of fataling later.) - In the false branch, throw a
\Bitrix\Main\LoaderExceptionwhen the module is required, or set a fallback and skip the feature when the module is optional. (verify: Required-module failures raise a named exception; optional ones return a fallback.) - Only after the guard passes, reference the module's namespaced classes (for
example
\Bitrix\Iblock\ElementTable); autoloading is now wired up. (verify: The module's classes resolve without a class-not-found error.)
Best practices
- Guard every
Loader::includeModule('iblock')(or legacyCModule::IncludeModule) with a check on its boolean return, and bail out early when the module is missing - When a module is required for the code to work at all, fail fast — throw a
\Bitrix\Main\LoaderExceptionor a\RuntimeExceptionimmediately after a false return — instead of continuing and letting a later call fatal - Include a module once near the top of the entry point (controller, component, agent) that needs it, not repeatedly deep inside loops or helper functions; the Loader already caches the result, so scatter buys nothing and hides dependencies
- When a module powers only an optional feature, branch on the false return and degrade gracefully — hide the feature or use a fallback — rather than throwing
- For a custom module's classes that live outside the PSR-4
lib/convention, map them withLoader::registerAutoLoadClasses('vendor.module', [...])inside the module'sinclude.phpinstead of hand-writingrequirecalls
Anti-patterns
| Anti-pattern | Why it fails | Do instead |
| require-ing module files by hand instead of using the Loader | Manual requires break when the module's file layout changes, skip the module's<br>own initialization, and defeat the autoload map. | Call Loader::includeModule('iblock') and let autoloading resolve the class on<br>first use. |
| Suppressing the loader failure with error control | Silencing the failure only defers the crash to the first class use, where the<br>error message no longer names the missing module. | Handle the false return or exception explicitly — log it, then throw for required<br>modules or degrade for optional ones. |
| Ignoring the includeModule return value | When the module is absent the call returns false and the next class reference fatals. | Branch on the boolean result and stop with a clear message or fallback when the<br>module is missing. |
See references/anti-patterns.md.
Common mistakes
- Referencing module classes before the module is included — Using a module class such as
\Bitrix\Iblock\ElementTablebeforeLoader::includeModule('iblock')has run throws a fatal "class not found". Fix: Include the module first and check the boolean result; reference its classes only after a successful inclusion, returning a handled error otherwise. - Calling the Loader before the kernel is bootstrapped — In a standalone CLI script or cron entry, calling
Loader::includeModule()before including the Bitrix kernel prologue fails because the Loader class itself is not yet defined. Fix: Require the kernel bootstrap (for example the site'sprolog_before.php/ DocumentRoot bootstrap) at the top of the script, then call the Loader. - Passing the wrong module identifier —
includeModulesilently returns false for a mistyped or wrong identifier —catalogvssale, or a custom module's folder name vs itsvendor.moduleid — so the module never loads and later class use fatals. Fix: Use the exact module identifier (the folder name underbitrix/modules, e.g.vendor.mymodule), and treat a false return as "not available" rather than assuming a typo cannot happen.
Version notes
- The D7 Loader supersedes CModule::IncludeModule —
\Bitrix\Main\Loader::includeModule()is the current D7 way to include a module; the legacyCModule::IncludeModule()remains available as a thin compatibility wrapper over the same mechanism for older code.
Security
- Not applicable — no I/O, auth, or untrusted input.
Testing
- Activation and decision behavior are verified in
eval/scenarios/bitrix/d7-loader.yaml.
Additional resources
- references/anti-patterns.md
- references/core.md
- references/examples.md
- references/pitfalls.md
- references/recipes.md
- references/version-differences.md
Knowledge graph
Prerequisites: bitrix/kernel-main-module
Related: bitrix/d7-events
<!-- graph-fragment: graph/fragments/bitrix/d7-loader.yaml -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

