-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.php
More file actions
52 lines (46 loc) · 2.03 KB
/
Copy pathPlugin.php
File metadata and controls
52 lines (46 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php namespace JumpLink\PagesCompat;
use System\Classes\PluginBase;
/**
* JumpLink.PagesCompat
*
* Compatibility shim for migrating from RainLab.Pages to winter/wn-pages-plugin.
*
* Winter's Pages fork renames the namespace RainLab\Pages\* -> Winter\Pages\*.
* Third-party plugins written against RainLab.Pages that hard-reference its classes
* (e.g. Renatio.SeoManager's SeoStaticPage, which does
* `$model instanceof \RainLab\Pages\Classes\Page`) would otherwise break after the
* swap to Winter.Pages.
*
* On boot this registers a lightweight autoloader that lazily aliases any requested
* RainLab\Pages\Classes\<Name> onto the matching Winter\Pages\Classes\<Name> -- only
* when the Winter class exists and the legacy name is not already defined. It is a
* safe no-op while RainLab.Pages is still installed, or before Winter.Pages exists,
* and adds zero eager cost (the alias is created on first reference).
*/
class Plugin extends PluginBase
{
public function pluginDetails()
{
return [
'name' => 'JumpLink Pages Compat',
'description' => 'Aliases legacy RainLab\\Pages\\Classes\\* onto Winter\\Pages\\Classes\\* so plugins that hard-reference the old namespace keep working after migrating to winter/wn-pages-plugin.',
'author' => 'JumpLink – Art+Code Studio',
'icon' => 'icon-link',
'homepage' => 'https://github.com/ArtCodeStudio/wn-pages-compat-plugin',
];
}
public function boot()
{
$legacyPrefix = 'RainLab\\Pages\\Classes\\';
$winterPrefix = 'Winter\\Pages\\Classes\\';
spl_autoload_register(function (string $class) use ($legacyPrefix, $winterPrefix): void {
if (!str_starts_with($class, $legacyPrefix)) {
return;
}
$winterClass = $winterPrefix . substr($class, strlen($legacyPrefix));
if (class_exists($winterClass) && !class_exists($class, false)) {
class_alias($winterClass, $class);
}
});
}
}