diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-09-17 13:47:58 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-09-17 13:59:27 +0200 |
commit | 5eddde64860a77b2355aaf31044ab6692ed36265 (patch) | |
tree | 1c25b26228099f8f39f410f2bf25c35f8410ca18 /lib/private | |
parent | 4cff2f1ab398785ba7dc96c495706bb8b47b1307 (diff) | |
download | nextcloud-server-5eddde64860a77b2355aaf31044ab6692ed36265.tar.gz nextcloud-server-5eddde64860a77b2355aaf31044ab6692ed36265.zip |
Add a Sabre plugin that emits an event for apps
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/connector/sabre/listenerplugin.php | 59 | ||||
-rw-r--r-- | lib/private/connector/sabre/serverfactory.php | 6 |
2 files changed, 64 insertions, 1 deletions
diff --git a/lib/private/connector/sabre/listenerplugin.php b/lib/private/connector/sabre/listenerplugin.php new file mode 100644 index 00000000000..86cb8ebe568 --- /dev/null +++ b/lib/private/connector/sabre/listenerplugin.php @@ -0,0 +1,59 @@ +<?php +/** + * @author Joas Schilling <nickvergessen@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OC\Connector\Sabre; + +use Sabre\DAV\Server; +use Sabre\DAV\ServerPlugin; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; + +class ListenerPlugin extends ServerPlugin { + /** @var EventDispatcherInterface */ + protected $dispatcher; + + /** + * @param EventDispatcherInterface $dispatcher + */ + public function __construct(EventDispatcherInterface $dispatcher) { + $this->dispatcher = $dispatcher; + } + + /** + * This initialize the plugin + * + * @param Server $server + */ + public function initialize(Server $server) { + $server->on('beforeMethod', array($this, 'emitListener'), 15); + } + + /** + * This method is called before any HTTP method and returns http status code 503 + * in case the system is in maintenance mode. + * + * @return bool + */ + public function emitListener() { + $this->dispatcher->dispatch('OC\Connector\Sabre::beforeMethod'); + + return true; + } +} diff --git a/lib/private/connector/sabre/serverfactory.php b/lib/private/connector/sabre/serverfactory.php index 042cc051d35..54470b0b8aa 100644 --- a/lib/private/connector/sabre/serverfactory.php +++ b/lib/private/connector/sabre/serverfactory.php @@ -28,6 +28,7 @@ use OCP\ILogger; use OCP\ITagManager; use OCP\IUserSession; use Sabre\DAV\Auth\Backend\BackendInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; class ServerFactory { public function __construct( @@ -36,7 +37,8 @@ class ServerFactory { IDBConnection $databaseConnection, IUserSession $userSession, IMountManager $mountManager, - ITagManager $tagManager + ITagManager $tagManager, + EventDispatcherInterface $dispatcher ) { $this->config = $config; $this->logger = $logger; @@ -44,6 +46,7 @@ class ServerFactory { $this->userSession = $userSession; $this->mountManager = $mountManager; $this->tagManager = $tagManager; + $this->dispatcher = $dispatcher; } /** @@ -71,6 +74,7 @@ class ServerFactory { $server->addPlugin(new \OC\Connector\Sabre\FilesPlugin($objectTree)); $server->addPlugin(new \OC\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); $server->addPlugin(new \OC\Connector\Sabre\LockPlugin($objectTree)); + $server->addPlugin(new \OC\Connector\Sabre\ListenerPlugin($this->dispatcher)); // wait with registering these until auth is handled and the filesystem is setup $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |