Merge pull request #19123 from owncloud/listener-sabre-plugin

Add a Sabre plugin that emits an event
This commit is contained in:
Thomas Müller 2015-09-17 18:03:15 +02:00
commit c74da41faf
5 changed files with 69 additions and 4 deletions

View File

@ -39,7 +39,8 @@ $serverFactory = new \OC\Connector\Sabre\ServerFactory(
\OC::$server->getDatabaseConnection(), \OC::$server->getDatabaseConnection(),
\OC::$server->getUserSession(), \OC::$server->getUserSession(),
\OC::$server->getMountManager(), \OC::$server->getMountManager(),
\OC::$server->getTagManager() \OC::$server->getTagManager(),
\OC::$server->getEventDispatcher()
); );
// Backends // Backends

View File

@ -39,7 +39,8 @@ $serverFactory = new \OC\Connector\Sabre\ServerFactory(
\OC::$server->getDatabaseConnection(), \OC::$server->getDatabaseConnection(),
\OC::$server->getUserSession(), \OC::$server->getUserSession(),
\OC::$server->getMountManager(), \OC::$server->getMountManager(),
\OC::$server->getTagManager() \OC::$server->getTagManager(),
\OC::$server->getEventDispatcher()
); );
$requestUri = \OC::$server->getRequest()->getRequestUri(); $requestUri = \OC::$server->getRequest()->getRequestUri();

View File

@ -0,0 +1,58 @@
<?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\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 \Sabre\DAV\Server $server
*/
public function initialize(\Sabre\DAV\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;
}
}

View File

@ -28,6 +28,7 @@ use OCP\ILogger;
use OCP\ITagManager; use OCP\ITagManager;
use OCP\IUserSession; use OCP\IUserSession;
use Sabre\DAV\Auth\Backend\BackendInterface; use Sabre\DAV\Auth\Backend\BackendInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class ServerFactory { class ServerFactory {
public function __construct( public function __construct(
@ -36,7 +37,8 @@ class ServerFactory {
IDBConnection $databaseConnection, IDBConnection $databaseConnection,
IUserSession $userSession, IUserSession $userSession,
IMountManager $mountManager, IMountManager $mountManager,
ITagManager $tagManager ITagManager $tagManager,
EventDispatcherInterface $dispatcher
) { ) {
$this->config = $config; $this->config = $config;
$this->logger = $logger; $this->logger = $logger;
@ -44,6 +46,7 @@ class ServerFactory {
$this->userSession = $userSession; $this->userSession = $userSession;
$this->mountManager = $mountManager; $this->mountManager = $mountManager;
$this->tagManager = $tagManager; $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\FilesPlugin($objectTree));
$server->addPlugin(new \OC\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); $server->addPlugin(new \OC\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger));
$server->addPlugin(new \OC\Connector\Sabre\LockPlugin($objectTree)); $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 // wait with registering these until auth is handled and the filesystem is setup
$server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) {

View File

@ -45,7 +45,8 @@ abstract class RequestTest extends TestCase {
\OC::$server->getDatabaseConnection(), \OC::$server->getDatabaseConnection(),
\OC::$server->getUserSession(), \OC::$server->getUserSession(),
\OC::$server->getMountManager(), \OC::$server->getMountManager(),
\OC::$server->getTagManager() \OC::$server->getTagManager(),
\OC::$server->getEventDispatcher()
); );
} }