Skip to content

Stop using getService for lexicon, registry, error, smarty, mail, and hashing - #16985

Open
Ibochkarev wants to merge 6 commits into
modxcms:3.xfrom
Ibochkarev:fix/15986-remove-getservice-core
Open

Stop using getService for lexicon, registry, error, smarty, mail, and hashing#16985
Ibochkarev wants to merge 6 commits into
modxcms:3.xfrom
Ibochkarev:fix/15986-remove-getservice-core

Conversation

@Ibochkarev

@Ibochkarev Ibochkarev commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

What changed and why

getService() is deprecated, but core and manager still used it as a lazy factory for built-in services. This PR finishes tiers 1–2 from the plan on #15986: stop calling it for six names in core/src and manager.

That work sits on the MAB-03 stack (xPDO 3 via Composer, autoloading, fewer map-era habits). Here we push the same direction for runtime services: register them on the DI container / accessors instead of the old xPDO service locator.

Tier 1 — lexicon, registry, error

  • registerCoreServices() registers registry, error, and hashing during initialize() (lexicon already comes from _initCulture)
  • Call sites use $modx->services->get(…) or the synced $modx->registry / $modx->lexicon / $modx->error properties

Tier 2 — smarty, mail, hashing

  • hashing is eager (password paths need it)
  • getSmarty() / getMail() / getManagerTemplatePath() are the canonical accessors; smarty/mail register on first use
  • Manager request forces the theme template path; other call sites keep first-wins via getSmarty($path)
  • modX::getService() still works for extras/tests and syncs $modx->$name when the service was already in the container

Grep gate for those six names under core/src and manager is empty.

How to test

  1. rg "getService\s*\(\s*['\"](lexicon|registry|error|smarty|mail|hashing)" core/src manager → empty
  2. Manager login, including forgot-password / activation hash (registry)
  3. Edit/save a resource (locks use registry)
  4. Open the dashboard (widgets use smarty)
  5. Create/update a user with email notification (smarty tpl + mail)
  6. Change a user password (hashing)
  7. CI PHPUnit / MySQL checks on this branch

Related issue(s)/PR(s)

Compatibility notes

Extras that still call getService() for these names keep working. Core prefers accessors and container/$modx->* properties after a normal initialize().

Breaking change assessment

No public signature removals. New helpers: getSmarty(), getMail(), getManagerTemplatePath(), registerCoreServices().

Calling getService('lexicon') before initialize() / _initCulture() was already unsupported.

Test coverage

Controller test harnesses now use getSmarty(). No new dedicated unit tests. Grep gate + PHPUnit + the manual smoke list above.

Contributors

Thanks @BobRay for filing #15986 and pointing out the container did not already hold these services.

AI tool use

Cursor helped inventory call sites, apply the changes, and draft this PR. Human review still required.

Register modError during initialize next to registry (lexicon already
comes from _initCulture). Replace core/manager getService call sites
for those three services with the DI container or synced properties.

Part of the series planned on modxcms#15986 (tier 1).
Register hashing eagerly and mail/smarty as lazy shared DI services
during initialize, then replace remaining core/manager call sites so
tiers 1–2 of modxcms#15986 ship in one PR.
@Ibochkarev Ibochkarev changed the title Stop using getService for lexicon, registry, and error Stop using getService for lexicon, registry, error, smarty, mail, and hashing Aug 10, 2026
Extract _registerCoreServices, add getSmarty/getMail/getManagerTemplatePath,
drop duplicated smarty bootstraps and dead widget ensures, and simplify
Reload registry handling.
Do not pre-register mail/smarty (keeps getService param+property sync),
ensure widgets call getSmarty(), sync properties in modX::getService,
and resolve hashing on plain xPDO without touching a missing property.
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