| 1 |
<?php |
| 2 |
/** |
| 3 |
* Display conditions module (spec 034-display-conditions). |
| 4 |
* |
| 5 |
* Relocated: includes/API/Conditions.php (the REST controller — 4 endpoints: |
| 6 |
* conditions/check-conditions/save-conditions/autocomplete-condition) + |
| 7 |
* includes/Builder/Managers/ConditionManager.php + Cache.php (the condition |
| 8 |
* evaluation engine + its wp_options cache) + includes/Builder/Conditions/ |
| 9 |
* (the 14-file condition-type hierarchy: Archive, Condition (base), Error, |
| 10 |
* Front, General, Page, Post, PostByAuthor, PostTypeArchive, ProductSearch, |
| 11 |
* Search, Singular, Taxonomy, WooCommerce). Namespace: |
| 12 |
* Templately\API\Conditions -> this module's REST\Conditions; |
| 13 |
* Templately\Builder\Managers\{ConditionManager,Cache} -> this module's |
| 14 |
* Managers\*; Templately\Builder\Conditions\* -> this module's Conditions\*. |
| 15 |
* |
| 16 |
* ConditionManager + Cache are explicitly attributed to this spec by spec |
| 17 |
* 035-theme-builder's own FR-030 ("the existing condition/location engine |
| 18 |
* (ConditionManager + Cache, FR-009, spec 034) MUST remain the sole source |
| 19 |
* of truth...") and spec 035's Depends On (032, 033, 034) — 035 CONSUMES |
| 20 |
* this module's engine, so it had to be extracted first, even though 035's |
| 21 |
* own Ownership section also lists ConditionManager+Cache among the |
| 22 |
* "Server-Side Logic" it touches (035 is a consumer, not the owner). |
| 23 |
* |
| 24 |
* NOT relocated (at 034 time): ThemeBuilder.php, TemplateManager, |
| 25 |
* LocationManager, PageTemplates, Source, Types/*, Platforms/*, Render/* — |
| 26 |
* all spec 035-theme-builder's territory. ConditionManager keeps a |
| 27 |
* cross-module reference to ThemeBuilder (constructor takes the builder |
| 28 |
* instance) and ThemeTemplate (docblock type). |
| 29 |
* |
| 30 |
* UPDATE (spec 035, 2026-07-05): the whole `includes/Builder/` tree named |
| 31 |
* above has SINCE relocated to `modules/theme-builder/` — this module's own |
| 32 |
* cross-references now import `Templately\Modules\ThemeBuilder\{ThemeBuilder, |
| 33 |
* Types\ThemeTemplate,Source}` accordingly. This docblock's namespace |
| 34 |
* mentions above (`Templately\Builder\...`) describe the state AT THE TIME |
| 35 |
* of the 034 move, not the current tree — see modules/theme-builder/CLAUDE.md |
| 36 |
* for the current home of everything theme-builder owns. |
| 37 |
* |
| 38 |
* No boot-ordering fix needed here (unlike 032/033's platform drivers): |
| 39 |
* Conditions.php was eagerly instantiated in Plugin::apis() (during |
| 40 |
* plugins_loaded) purely to self-register into the platform-adapter `Platform_Registry::add($this, |
| 41 |
* 'API')` registry — a registration that Plugin::register_routes() explicitly |
| 42 |
* SKIPS for any Templately\Modules\* class already (see its own skip-comment). |
| 43 |
* So the eager call was simply removed from Plugin::apis(); this module's |
| 44 |
* register_rest_routes() (below) wires the real route registration on |
| 45 |
* rest_api_init via Module_Base::boot_rest_routes(), the same lazy pattern |
| 46 |
* every other module-owned REST class uses (013-033) — no autoloader-timing |
| 47 |
* hazard exists for a class only ever resolved at rest_api_init. |
| 48 |
* |
| 49 |
* @package Templately |
| 50 |
*/ |
| 51 |
|
| 52 |
namespace Templately\Modules\DisplayConditions; |
| 53 |
|
| 54 |
use Templately\Core\Module_Base; |
| 55 |
use Templately\Modules\DisplayConditions\REST\Conditions; |
| 56 |
use Templately\Modules\DisplayConditions\Managers\ConditionManager; |
| 57 |
|
| 58 |
class Module extends Module_Base { |
| 59 |
|
| 60 |
public function get_name(): string { |
| 61 |
return 'display-conditions'; |
| 62 |
} |
| 63 |
|
| 64 |
public function get_dependencies(): array { |
| 65 |
// theme-builder. ConditionManager was extracted FROM theme-builder in spec 034 |
| 66 |
// and consumes its types: ConditionManager/Cache/Condition + the REST controller |
| 67 |
// reference theme-builder's ThemeBuilder / Source / ThemeTemplate. The former |
| 68 |
// reverse edge (theme-builder -> display-conditions) is removed: theme-builder |
| 69 |
// now obtains ConditionManager through the `templately_condition_manager` filter |
| 70 |
// registered below, so the dependency is one-directional (no declared cycle). |
| 71 |
return [ 'theme-builder' ]; |
| 72 |
} |
| 73 |
|
| 74 |
protected function init_hooks(): void { |
| 75 |
// Supply the ConditionManager to theme-builder through a filter seam instead of |
| 76 |
// theme-builder importing this module's namespace directly (cycle inversion). |
| 77 |
// ThemeBuilder::source_register() applies this on `init`; init_hooks() runs at |
| 78 |
// `plugins_loaded` (Modules_Manager::boot()), so the filter is always registered |
| 79 |
// before it is applied. |
| 80 |
add_filter( 'templately_condition_manager', [ $this, 'provide_condition_manager' ], 10, 2 ); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Provide the ConditionManager for the theme-builder module. |
| 85 |
* |
| 86 |
* @param ConditionManager|null $manager Existing manager, if any upstream filter already supplied one. |
| 87 |
* @param mixed $builder The ThemeBuilder instance requesting the manager. |
| 88 |
* @return ConditionManager |
| 89 |
*/ |
| 90 |
public function provide_condition_manager( $manager, $builder ) { |
| 91 |
return $manager instanceof ConditionManager ? $manager : new ConditionManager( $builder ); |
| 92 |
} |
| 93 |
|
| 94 |
public function register_rest_routes(): void { |
| 95 |
Conditions::get_instance()->register_routes(); |
| 96 |
} |
| 97 |
} |
| 98 |
|