Skip to content

Vendor-scope the Str macros and add a registry-free Identifiers API - #5

Merged
imanimanyara merged 1 commit into
masterfrom
fix/vendor-scoped-str-macros
Oct 6, 2026
Merged

imanimanyara merged 1 commit into
masterfrom
fix/vendor-scoped-str-macros

Conversation

@imanimanyara

Copy link
Copy Markdown
Member

Why

Str's macro registry is a flat static map (Macroable::macro() is static::$macros[$name] = $macro;), so the bare Str::sku(), Str::orderNumber() and Str::ticketNumber() registered in 0.1.0 are silently replaced by any other package or application registering the same names, and vice versa. The model generators also resolved their values through those macros (Str::{$this->strMixin}()), so such a registration changed what every HasSku / HasOrderNumber / HasTicketNumber model wrote.

What

  • Simtabi\Lacommerce\Supports\Identifiers: a final class with static sku(), orderNumber() and ticketNumber(), with no registry in the path. It is now the primary API, and the shipped generators call it directly. A custom generator naming another $strMixin still has that macro called.
  • Scoped macros Str::simtabiLacommerceSku(), Str::simtabiLacommerceOrderNumber() and Str::simtabiLacommerceTicketNumber(), with the bare signatures, so migrating is a rename. Vendor and package are both in the name, and camel case is used because a macro name is called as a PHP method and cannot hold / or -.
  • Bare macros kept, deprecated: they forward to the scoped macros with the same arguments and output, and raise one E_USER_DEPRECATED per name per boot. Earliest removal: 0.2.0.
  • register_legacy_macros (default true) lets a host stop registering the bare names.
  • The macro bodies moved from the provider to Supports\StrMacros. No name collides with a real Str method on Laravel 12.69 (a test asserts this).

Behaviour

  • The bare macros' output format and arguments are unchanged, and tests pin them: the XXX- + 10-digit shape, the configured-separator fallback for an empty or null separator, orderNumber ignoring $source and defaulting to ORD, and the ignored $prefix on sku/ticketNumber.
  • One intended change: the traits no longer go through Str::sku() etc. An application that deliberately overrode a bare macro to customise generated values loses that effect. The documented customisation point, the generator config class, is unaffected.

Tests

48 tests (up from 22). The new ones cover the pinned bare behaviour, Identifiers, the scoped macros, alias delegation (scoped macros replaced, bare follow), one deprecation per name per boot, the opt-out flag (traits still generate with the bare names unregistered), and that a hijacked Str::sku no longer changes trait output. I checked that two guards fail under mutation: pointing the generator back at Str::sku fails the hijack and opt-out tests, and defaulting the flag to false fails 12 tests.

Str's macro registry is one flat static map keyed by name, so the bare
Str::sku(), Str::orderNumber() and Str::ticketNumber() could be silently
replaced by any other package or the host application. Worse, the model
generators called those macros, so such a registration changed every SKU,
order number and ticket number the traits wrote.

Supports\Identifiers now holds the logic as a final class with no registry
in the path, and the shipped generators call it directly. The macros are
registered as Str::simtabiLacommerce{Sku,OrderNumber,TicketNumber}() with
the bare signatures. The bare names stay registered as deprecated aliases
that forward with the same arguments and output and raise one
E_USER_DEPRECATED per name per boot; register_legacy_macros (default true)
lets a host stop registering them. Earliest removal: 0.2.0.
Copilot AI balanced review requested due to automatic review settings October 6, 2026 11:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@imanimanyara
imanimanyara merged commit c119f91 into master Oct 6, 2026
6 checks passed
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.

2 participants