agentleFS
AnyOrgNameAnyOrgName/php-skills/skills/bitrix/d7-loader/SKILL.md

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, битрикс, модуль, загрузчик.

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
  1. Distinctive:

    Do not use this skill to bootstrap the kernel, read the Request, or resolve Application/Context services — that is the kernel (main module) …

    line 74
  2. Very specific:

    Do not use this skill on a non-Bitrix PHP app (plain PHP, Laravel, Symfony).

    line 77
  3. Very specific:

    Only after the guard passes, reference the module's namespaced classes (for example \Bitrix\Iblock\ElementTable).

    line 93
  4. Very specific:

    When a module is required for the code to work at all, fail fast — throw a \Bitrix\Main\LoaderException or a \RuntimeException immediately …

    line 101
  5. Distinctive:

    When a module powers only an optional feature, branch on the false return and degrade gracefully — hide the feature or use a fallback — …

    line 107
  6. Distinctive:

    Not applicable — no I/O, auth, or untrusted input.

    line 146

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- 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 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.

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\Loader and 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 legacy CModule::IncludeModule(); both include the module, but the D7 Loader is the namespaced, current API.

Quick recipe

  1. 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 missing iblock module reaches the false branch instead of fataling later.)
  2. In the false branch, throw a \Bitrix\Main\LoaderException when 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.)
  3. 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 legacy CModule::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\LoaderException or a \RuntimeException immediately 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 with Loader::registerAutoLoadClasses('vendor.module', [...]) inside the module's include.php instead of hand-writing require calls

Anti-patterns

Anti-patternWhy it failsDo instead
require-ing module files by hand instead of using the LoaderManual 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 controlSilencing 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 valueWhen 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

  1. Referencing module classes before the module is included — Using a module class such as \Bitrix\Iblock\ElementTable before Loader::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.
  2. 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's prolog_before.php / DocumentRoot bootstrap) at the top of the script, then call the Loader.
  3. Passing the wrong module identifier — includeModule silently returns false for a mistyped or wrong identifier — catalog vs sale, or a custom module's folder name vs its vendor.module id — so the module never loads and later class use fatals. Fix: Use the exact module identifier (the folder name under bitrix/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 legacy CModule::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 -->

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.