Skip to content

Commit 2c059dd

Browse files
authored
Merge pull request #44952 from nextcloud/perf/44951/template-creator
perf(templates): Emit RegisterTemplateCreatorEvent to register template creators more lazy
2 parents 26cd6a3 + f9e235f commit 2c059dd

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@
431431
'OCP\\Files\\Template\\FileCreatedFromTemplateEvent' => $baseDir . '/lib/public/Files/Template/FileCreatedFromTemplateEvent.php',
432432
'OCP\\Files\\Template\\ICustomTemplateProvider' => $baseDir . '/lib/public/Files/Template/ICustomTemplateProvider.php',
433433
'OCP\\Files\\Template\\ITemplateManager' => $baseDir . '/lib/public/Files/Template/ITemplateManager.php',
434+
'OCP\\Files\\Template\\RegisterTemplateCreatorEvent' => $baseDir . '/lib/public/Files/Template/RegisterTemplateCreatorEvent.php',
434435
'OCP\\Files\\Template\\Template' => $baseDir . '/lib/public/Files/Template/Template.php',
435436
'OCP\\Files\\Template\\TemplateFileCreator' => $baseDir . '/lib/public/Files/Template/TemplateFileCreator.php',
436437
'OCP\\Files\\UnseekableException' => $baseDir . '/lib/public/Files/UnseekableException.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
464464
'OCP\\Files\\Template\\FileCreatedFromTemplateEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Template/FileCreatedFromTemplateEvent.php',
465465
'OCP\\Files\\Template\\ICustomTemplateProvider' => __DIR__ . '/../../..' . '/lib/public/Files/Template/ICustomTemplateProvider.php',
466466
'OCP\\Files\\Template\\ITemplateManager' => __DIR__ . '/../../..' . '/lib/public/Files/Template/ITemplateManager.php',
467+
'OCP\\Files\\Template\\RegisterTemplateCreatorEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Template/RegisterTemplateCreatorEvent.php',
467468
'OCP\\Files\\Template\\Template' => __DIR__ . '/../../..' . '/lib/public/Files/Template/Template.php',
468469
'OCP\\Files\\Template\\TemplateFileCreator' => __DIR__ . '/../../..' . '/lib/public/Files/Template/TemplateFileCreator.php',
469470
'OCP\\Files\\UnseekableException' => __DIR__ . '/../../..' . '/lib/public/Files/UnseekableException.php',

lib/private/Files/Template/TemplateManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use OCP\Files\Template\FileCreatedFromTemplateEvent;
4141
use OCP\Files\Template\ICustomTemplateProvider;
4242
use OCP\Files\Template\ITemplateManager;
43+
use OCP\Files\Template\RegisterTemplateCreatorEvent;
4344
use OCP\Files\Template\Template;
4445
use OCP\Files\Template\TemplateFileCreator;
4546
use OCP\IConfig;
@@ -119,6 +120,7 @@ public function getTypes(): array {
119120
if (!empty($this->types)) {
120121
return $this->types;
121122
}
123+
$this->eventDispatcher->dispatchTyped(new RegisterTemplateCreatorEvent($this));
122124
foreach ($this->registeredTypes as $registeredType) {
123125
$this->types[] = $registeredType();
124126
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2024 Julius Härtl <jus@bitgrid.net>
4+
*
5+
* @author Julius Härtl <jus@bitgrid.net>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
namespace OCP\Files\Template;
24+
25+
use OCP\EventDispatcher\Event;
26+
27+
/**
28+
* @since 30.0.0
29+
*/
30+
class RegisterTemplateCreatorEvent extends Event {
31+
32+
/**
33+
* @since 30.0.0
34+
*/
35+
public function __construct(
36+
private ITemplateManager $templateManager
37+
) {
38+
}
39+
40+
/**
41+
* @since 30.0.0
42+
*/
43+
public function getTemplateManager(): ITemplateManager {
44+
return $this->templateManager;
45+
}
46+
}

0 commit comments

Comments
 (0)