-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfau-degree-program.php
175 lines (158 loc) · 5.39 KB
/
fau-degree-program.php
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* Plugin Name: FAU Degree Program Management
* Plugin URI: https://github.com/RRZE-Webteam/FAU-Studium
* Description: Add and edit degree programs and expose them via the REST API.
* Version: 2.2.0-beta.1
* Author: Syde GmbH
* Author URI: https://syde.com/
* Update URI: false
* GitHub Plugin URI: RRZE-Webteam/FAU-Studium
* License: GPL-2.0-or-later
* Text Domain: fau-degree-program
* Domain Path: /languages
*/
declare(strict_types=1);
namespace Fau\DegreeProgram;
// phpcs:disable PSR1.Files.SideEffects
use Fau\DegreeProgram\Infrastructure\Authorization\AuthorizationModule;
use Fau\DegreeProgram\Infrastructure\Authorization\UserRolesModifier;
use Fau\DegreeProgram\Infrastructure\Authorization\UserRolesRegistrar;
use Fau\DegreeProgram\Infrastructure\Authorization\WorkflowAuthor\WorkflowAuthorModule;
use Fau\DegreeProgram\Infrastructure\Cache\CacheModule;
use Fau\DegreeProgram\Infrastructure\CliModule;
use Fau\DegreeProgram\Infrastructure\Command\CommandModule;
use Fau\DegreeProgram\Infrastructure\Content\ContentModule;
use Fau\DegreeProgram\Infrastructure\Dashboard\AdminBarModule;
use Fau\DegreeProgram\Infrastructure\Dashboard\DegreeProgramEditor\DegreeProgramEditorModule;
use Fau\DegreeProgram\Infrastructure\Dashboard\DegreeProgramListTable\DegreeProgramListTableModule;
use Fau\DegreeProgram\Infrastructure\Dashboard\Settings\SettingsModule;
use Fau\DegreeProgram\Infrastructure\Dashboard\TermMeta\TermMetaModule;
use Fau\DegreeProgram\Infrastructure\EventDispatcherModule;
use Fau\DegreeProgram\Infrastructure\LoggerModule;
use Fau\DegreeProgram\Infrastructure\Migration\MigrationModule;
use Fau\DegreeProgram\Infrastructure\Patches\PatchesModule;
use Fau\DegreeProgram\Infrastructure\QueueModule;
use Fau\DegreeProgram\Infrastructure\Repository\RepositoryModule;
use Fau\DegreeProgram\Infrastructure\RestApi\RestApiModule;
use Fau\DegreeProgram\Infrastructure\Revision\Notification\RevisionNotificationModule;
use Fau\DegreeProgram\Infrastructure\Revision\RevisionModule;
use Fau\DegreeProgram\Infrastructure\SanitizerModule;
use Fau\DegreeProgram\Infrastructure\TranslationModule;
use Inpsyde\Modularity\Package;
use Inpsyde\Modularity\Properties\PluginProperties;
use RuntimeException;
use Throwable;
/**
* Display an error message in the WP admin.
*
* @param string $message The message content
*
* @return void
*/
function errorNotice(string $message): void
{
add_action(
'all_admin_notices',
static function () use ($message) {
$class = 'notice notice-error';
printf(
'<div class="%1$s"><p>%2$s</p></div>',
esc_attr($class),
wp_kses_post($message)
);
}
);
}
/**
* Handle any exception that might occur during plugin setup.
*
* @param Throwable $throwable The Exception
*
* @return void
*/
function handleException(Throwable $throwable): void
{
do_action('fau.degree-program.critical', $throwable);
errorNotice(
sprintf(
'<strong>Error:</strong> %s <br><pre>%s</pre>',
$throwable->getMessage(),
$throwable->getTraceAsString()
)
);
}
/**
* Provide the plugin instance.
*
* @link https://github.com/inpsyde/modularity#access-from-external
*/
function plugin(): Package
{
/** @var Package|null $package */
static $package;
if (!$package) {
$properties = PluginProperties::new(__FILE__);
$package = Package::new($properties);
}
return $package;
}
function setUpAutoloader(): void
{
if (class_exists(ContentModule::class)) {
return;
}
if (!is_readable(__DIR__ . '/vendor/autoload.php')) {
throw new RuntimeException('Composer autoload file does not exist.');
}
require_once __DIR__ . '/vendor/autoload.php';
}
/**
* Initialize plugin.
*
* @throws Throwable
*/
function initialize(): void
{
try {
setUpAutoloader();
// Initialize plugin
plugin()
->addModule(new TranslationModule())
->addModule(new ContentModule())
->addModule(new TermMetaModule())
->addModule(new SettingsModule())
->addModule(new RevisionModule(__FILE__))
->addModule(new RepositoryModule())
->addModule(new CommandModule())
->addModule(new DegreeProgramEditorModule())
->addModule(new RestApiModule(
__DIR__ . '/vendor/rrze/fau-studium-common/config',
))
->addModule(new LoggerModule())
->addModule(new SanitizerModule())
->addModule(new EventDispatcherModule())
->addModule(new CacheModule())
->addModule(new CliModule())
->addModule(new AdminBarModule())
->addModule(new QueueModule())
->addModule(new WorkflowAuthorModule())
->addModule(new AuthorizationModule())
->addModule(new MigrationModule())
->addModule(new RevisionNotificationModule())
->addModule(new PatchesModule())
->addModule(new DegreeProgramListTableModule())
->boot();
} catch (Throwable $throwable) {
handleException($throwable);
}
}
add_action('plugins_loaded', __NAMESPACE__ . '\\initialize');
register_activation_hook(
__FILE__,
static function (): void {
setUpAutoloader();
UserRolesRegistrar::register();
UserRolesModifier::modify();
},
);