summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2021-07-30 09:33:33 +0200
committerGitHub <noreply@github.com>2021-07-30 09:33:33 +0200
commit79ef8b4c4a673143e016456e08537b57e60821d2 (patch)
tree7c70bb76d541845e565811faf44393e93f2fa4c8
parent97f84aa334609f22b9ba6b4dfe69955ef436c2d1 (diff)
parent42a17065a386ed2d0c6691b9de06688f595fe03d (diff)
Merge pull request #2364 from nextcloud/enh/1831/bye-bye-app.php
-rw-r--r--appinfo/app.php27
-rw-r--r--lib/AppInfo/Application.php37
-rw-r--r--lib/Dav/PatchPlugin.php8
3 files changed, 25 insertions, 47 deletions
diff --git a/appinfo/app.php b/appinfo/app.php
deleted file mode 100644
index f9e8863b..00000000
--- a/appinfo/app.php
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-use OCA\Contacts\AppInfo\Application;
-
-$app = \OC::$server->query(Application::class);
-$app->register();
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index e949cb69..e58cab05 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -26,12 +26,15 @@ use OCA\Contacts\Dav\PatchPlugin;
use OCA\Contacts\Listener\LoadContactsFilesActions;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\AppFramework\App;
+use OCP\AppFramework\Bootstrap\IBootContext;
+use OCP\AppFramework\Bootstrap\IBootstrap;
+use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\SabrePluginEvent;
-class Application extends App {
+class Application extends App implements IBootstrap {
public const APP_ID = 'contacts';
-
+
public const AVAIL_SETTINGS = [
'allowSocialSync' => 'yes',
];
@@ -40,23 +43,25 @@ class Application extends App {
parent::__construct(self::APP_ID);
}
- public function register() {
- $server = $this->getContainer()->getServer();
+ public function register(IRegistrationContext $context): void {
+ $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadContactsFilesActions::class);
+ }
+
+ public function boot(IBootContext $context): void {
+ $appContainer = $context->getAppContainer();
+ $serverContainer = $context->getServerContainer();
/** @var IEventDispatcher $eventDispatcher */
- $eventDispatcher = $server->query(IEventDispatcher::class);
- $eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) {
- $server = $event->getServer();
-
- if ($server !== null) {
- // We have to register the PatchPlugin here and not info.xml,
- // because info.xml plugins are loaded, after the
- // beforeMethod:* hook has already been emitted.
- $server->addPlugin($this->getContainer()->query(PatchPlugin::class));
+ $eventDispatcher = $serverContainer->get(IEventDispatcher::class);
+ $eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', static function (SabrePluginEvent $event) use ($appContainer) {
+ if ($event->getServer() === null) {
+ return;
}
- });
- // Register files action
- $eventDispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadContactsFilesActions::class);
+ // We have to register the PatchPlugin here and not info.xml,
+ // because info.xml plugins are loaded, after the
+ // beforeMethod:* hook has already been emitted.
+ $event->getServer()->addPlugin($appContainer->get(PatchPlugin::class));
+ });
}
}
diff --git a/lib/Dav/PatchPlugin.php b/lib/Dav/PatchPlugin.php
index 16c25246..9f4f9d1f 100644
--- a/lib/Dav/PatchPlugin.php
+++ b/lib/Dav/PatchPlugin.php
@@ -87,9 +87,9 @@ class PatchPlugin extends ServerPlugin {
*
* @param PropPatch $propPatch
* @param INode $node
- * @return void
+ * @return bool
*/
- public function httpPatch(RequestInterface $request, ResponseInterface $response) {
+ public function httpPatch(RequestInterface $request, ResponseInterface $response): bool {
$path = $request->getPath();
$node = $this->server->tree->getNodeForPath($path);
@@ -127,7 +127,7 @@ class PatchPlugin extends ServerPlugin {
if (count($properties) > 1) {
throw new DAV\Exception\BadRequest('The specified property appear more than once');
}
-
+
// Init if not in the vcard
if (count($properties) === 0) {
$vCard->add($propertyName, $propertyData);
@@ -144,7 +144,7 @@ class PatchPlugin extends ServerPlugin {
$oldData = $properties[0]->getValue();
$properties[0]->setRawMimeDirValue($oldData.$propertyData);
}
-
+
// Validate & write
$vCard->validate();
$node->put($vCard->serialize());