本文整理匯總了PHP中Sabre\DAV\Server::addPlugin方法的典型用法代碼示例。如果您正苦於以下問題:PHP Server::addPlugin方法的具體用法?PHP Server::addPlugin怎麽用?PHP Server::addPlugin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sabre\DAV\Server
的用法示例。
在下文中一共展示了Server::addPlugin方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: init
function init()
{
if (!is_dir('store')) {
os_mkdir('store', STORAGE_DEFAULT_PERMISSIONS, false);
}
$which = null;
if (argc() > 1) {
$which = argv(1);
}
$profile = 0;
\App::$page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . z_root() . '/feed/' . $which . '" />' . "\r\n";
if ($which) {
profile_load($which, $profile);
}
$auth = new \Zotlabs\Storage\BasicAuth();
$ob_hash = get_observer_hash();
if ($ob_hash) {
if (local_channel()) {
$channel = \App::get_channel();
$auth->setCurrentUser($channel['channel_address']);
$auth->channel_id = $channel['channel_id'];
$auth->channel_hash = $channel['channel_hash'];
$auth->channel_account_id = $channel['channel_account_id'];
if ($channel['channel_timezone']) {
$auth->setTimezone($channel['channel_timezone']);
}
}
$auth->observer = $ob_hash;
}
if ($_GET['davguest']) {
$_SESSION['davguest'] = true;
}
$_SERVER['QUERY_STRING'] = str_replace(array('?f=', '&f='), array('', ''), $_SERVER['QUERY_STRING']);
$_SERVER['QUERY_STRING'] = strip_zids($_SERVER['QUERY_STRING']);
$_SERVER['QUERY_STRING'] = preg_replace('/[\\?&]davguest=(.*?)([\\?&]|$)/ism', '', $_SERVER['QUERY_STRING']);
$_SERVER['REQUEST_URI'] = str_replace(array('?f=', '&f='), array('', ''), $_SERVER['REQUEST_URI']);
$_SERVER['REQUEST_URI'] = strip_zids($_SERVER['REQUEST_URI']);
$_SERVER['REQUEST_URI'] = preg_replace('/[\\?&]davguest=(.*?)([\\?&]|$)/ism', '', $_SERVER['REQUEST_URI']);
$rootDirectory = new \Zotlabs\Storage\Directory('/', $auth);
// A SabreDAV server-object
$server = new SDAV\Server($rootDirectory);
// prevent overwriting changes each other with a lock backend
$lockBackend = new SDAV\Locks\Backend\File('store/[data]/locks');
$lockPlugin = new SDAV\Locks\Plugin($lockBackend);
$server->addPlugin($lockPlugin);
$is_readable = false;
// provide a directory view for the cloud in Hubzilla
$browser = new \Zotlabs\Storage\Browser($auth);
$auth->setBrowserPlugin($browser);
$server->addPlugin($browser);
// Experimental QuotaPlugin
// require_once('\Zotlabs\Storage/QuotaPlugin.php');
// $server->addPlugin(new \Zotlabs\Storage\\QuotaPlugin($auth));
ob_start();
// All we need to do now, is to fire up the server
$server->exec();
ob_end_flush();
killme();
}
示例2: setUp
function setUp()
{
$nodes = [new DAV\SimpleCollection('testdir')];
$this->server = new DAV\Server($nodes);
$this->plugin = new Plugin();
$this->plugin->allowAccessToNodesWithoutACL = false;
$this->server->addPlugin($this->plugin);
}
示例3: setUp
function setUp()
{
$nodes = array(new DAV\SimpleCollection('testdir'));
$this->server = new DAV\Server($nodes);
$aclPlugin = new Plugin();
$aclPlugin->allowAccessToNodesWithoutACL = true;
$this->server->addPlugin($aclPlugin);
}
示例4: setUp
function setUp()
{
$nodes = [new DAV\Mock\Collection('testdir', ['file1.txt' => 'contents'])];
$this->server = new DAV\Server($nodes);
$this->server->addPlugin(new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock()));
// Login
$this->server->getPlugin('auth')->beforeMethod(new \Sabre\HTTP\Request(), new \Sabre\HTTP\Response());
$aclPlugin = new Plugin();
$this->server->addPlugin($aclPlugin);
}
示例5: setUp
function setUp()
{
$nodes = [new DAV\SimpleCollection('testdir')];
$this->server = new DAV\Server($nodes);
$this->plugin = new Plugin();
$this->plugin->setDefaultAcl([]);
$this->server->addPlugin(new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock()));
// Login
$this->server->getPlugin('auth')->beforeMethod(new \Sabre\HTTP\Request(), new \Sabre\HTTP\Response());
$this->server->addPlugin($this->plugin);
}
示例6: indexAction
/**
* @param Request $request
*
* @return StreamedResponse
*/
public function indexAction(Request $request)
{
date_default_timezone_set('Europe/Paris');
$baseUri = $this->generateUrl('caldav');
$pmanager = $this->get('pmanager');
// Backends:
$authBackend = new Auth($pmanager);
$calendarBackend = new Calendar($pmanager, $this->generateUrl('event_read', [], true), $this->get('cocur_slugify'));
$principalBackend = new Principals($pmanager);
$tree = [new Collection($principalBackend), new CalendarRoot($principalBackend, $calendarBackend)];
$server = new Server($tree);
$server->setBaseUri($baseUri);
$server->addPlugin(new AuthPlugin($authBackend, 'SabreDAV'));
$server->addPlugin(new ACLPlugin());
$server->addPlugin(new ICSExportPlugin());
$server->addPlugin(new CalDAVPlugin());
$server->addPlugin(new SubscriptionsPlugin());
$server->addPlugin(new SchedulePlugin());
$server->addPlugin(new SyncPlugin());
$server->addPlugin(new BrowserPlugin());
$callback = function () use($server, $request) {
/* These two lines fix a weird bug
where SabreDAV wouldn't give the correct answer to a propfind */
$url = $server->httpRequest->getUrl();
$server->httpRequest = new SabreRequest($request->getMethod(), $url, $request->headers->all(), $request->getContent());
$server->exec();
/* These two lines log the request and the response */
$responseBody = $server->httpResponse->getBodyAsString();
$this->logIt($request, $server->httpResponse, $responseBody);
};
return new StreamedResponse($callback);
}
示例7: initServer
/**
* Initializes the server object
*
* @return void
*/
protected function initServer()
{
if ($this->authType === 'Basic') {
$authBackend = new \Baikal\Core\PDOBasicAuth($this->pdo, $this->authRealm);
} else {
$authBackend = new \Sabre\DAV\Auth\Backend\PDO($this->pdo, $this->authRealm);
}
$principalBackend = new \Sabre\DAVACL\PrincipalBackend\PDO($this->pdo);
$nodes = [new \Sabre\CalDAV\Principal\Collection($principalBackend)];
if ($this->enableCalDAV) {
$calendarBackend = new \Sabre\CalDAV\Backend\PDO($this->pdo);
$nodes[] = new \Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend);
}
if ($this->enableCardDAV) {
$carddavBackend = new \Sabre\CardDAV\Backend\PDO($GLOBALS["DB"]->getPDO());
$nodes[] = new \Sabre\CardDAV\AddressBookRoot($principalBackend, $carddavBackend);
}
$this->server = new \Sabre\DAV\Server($nodes);
$this->server->setBaseUri($this->baseUri);
$this->server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, $this->authRealm));
$this->server->addPlugin(new \Sabre\DAVACL\Plugin());
$this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
if ($this->enableCalDAV) {
$this->server->addPlugin(new \Sabre\CalDAV\Plugin());
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
}
if ($this->enableCardDAV) {
$this->server->addPlugin(new \Sabre\CardDAV\Plugin());
$this->server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
}
}
示例8: testPrepareResponses
public function testPrepareResponses()
{
$requestedProps = ['{DAV:}getcontentlength', '{http://owncloud.org/ns}fileid', '{DAV:}resourcetype'];
$node1 = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\Directory')->disableOriginalConstructor()->getMock();
$node2 = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\File')->disableOriginalConstructor()->getMock();
$node1->expects($this->once())->method('getInternalFileId')->will($this->returnValue('111'));
$node2->expects($this->once())->method('getInternalFileId')->will($this->returnValue('222'));
$node2->expects($this->once())->method('getSize')->will($this->returnValue(1024));
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view));
$this->plugin->initialize($this->server);
$responses = $this->plugin->prepareResponses($requestedProps, [$node1, $node2]);
$this->assertCount(2, $responses);
$this->assertEquals(200, $responses[0]->getHttpStatus());
$this->assertEquals(200, $responses[1]->getHttpStatus());
$props1 = $responses[0]->getResponseProperties();
$this->assertEquals('111', $props1[200]['{http://owncloud.org/ns}fileid']);
$this->assertNull($props1[404]['{DAV:}getcontentlength']);
$this->assertInstanceOf('\\Sabre\\DAV\\Xml\\Property\\ResourceType', $props1[200]['{DAV:}resourcetype']);
$resourceType1 = $props1[200]['{DAV:}resourcetype']->getValue();
$this->assertEquals('{DAV:}collection', $resourceType1[0]);
$props2 = $responses[1]->getResponseProperties();
$this->assertEquals('1024', $props2[200]['{DAV:}getcontentlength']);
$this->assertEquals('222', $props2[200]['{http://owncloud.org/ns}fileid']);
$this->assertInstanceOf('\\Sabre\\DAV\\Xml\\Property\\ResourceType', $props2[200]['{DAV:}resourcetype']);
$this->assertCount(0, $props2[200]['{DAV:}resourcetype']->getValue());
}
示例9: testLockEtc
function testLockEtc()
{
mkdir(SABRE_TEMPDIR . '/mstest');
$tree = new DAV\FS\Directory(SABRE_TEMPDIR . '/mstest');
$server = new DAV\Server($tree);
$server->debugExceptions = true;
$locksBackend = new Backend\File(SABRE_TEMPDIR . '/locksdb');
$locksPlugin = new Plugin($locksBackend);
$server->addPlugin($locksPlugin);
$response1 = new HTTP\ResponseMock();
$server->httpRequest = $this->getLockRequest();
$server->httpResponse = $response1;
$server->sapi = new HTTP\SapiMock();
$server->exec();
$this->assertEquals(201, $server->httpResponse->getStatus(), 'Full response body:' . $response1->getBodyAsString());
$this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token'));
$lockToken = $server->httpResponse->getHeader('Lock-Token');
//sleep(10);
$response2 = new HTTP\ResponseMock();
$server->httpRequest = $this->getLockRequest2();
$server->httpResponse = $response2;
$server->exec();
$this->assertEquals(201, $server->httpResponse->status);
$this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token'));
//sleep(10);
$response3 = new HTTP\ResponseMock();
$server->httpRequest = $this->getPutRequest($lockToken);
$server->httpResponse = $response3;
$server->exec();
$this->assertEquals(204, $server->httpResponse->status);
}
示例10: testLockEtc
function testLockEtc()
{
mkdir(SABRE_TEMPDIR . '/mstest');
$tree = new DAV\FS\Directory(SABRE_TEMPDIR . '/mstest');
$server = new DAV\Server($tree);
$server->debugExceptions = true;
$locksBackend = new Backend\File(SABRE_TEMPDIR . '/locksdb');
$locksPlugin = new Plugin($locksBackend);
$server->addPlugin($locksPlugin);
$response1 = new HTTP\ResponseMock();
$server->httpRequest = $this->getLockRequest();
$server->httpResponse = $response1;
$server->exec();
$this->assertEquals('HTTP/1.1 201 Created', $server->httpResponse->status);
$this->assertTrue(isset($server->httpResponse->headers['Lock-Token']));
$lockToken = $server->httpResponse->headers['Lock-Token'];
//sleep(10);
$response2 = new HTTP\ResponseMock();
$server->httpRequest = $this->getLockRequest2();
$server->httpResponse = $response2;
$server->exec();
$this->assertEquals('HTTP/1.1 201 Created', $server->httpResponse->status);
$this->assertTrue(isset($server->httpResponse->headers['Lock-Token']));
//sleep(10);
$response3 = new HTTP\ResponseMock();
$server->httpRequest = $this->getPutRequest($lockToken);
$server->httpResponse = $response3;
$server->exec();
$this->assertEquals('HTTP/1.1 204 No Content', $server->httpResponse->status);
}
示例11: testAdminAccess
/**
* @depends testNoAdminAccess
*/
function testAdminAccess()
{
$principalBackend = new PrincipalBackend\Mock();
$tree = array(new MockACLNode('adminonly', array()), new PrincipalCollection($principalBackend));
$fakeServer = new DAV\Server($tree);
$plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(), 'realm');
$fakeServer->addPlugin($plugin);
$plugin = new Plugin();
$plugin->adminPrincipals = array('principals/admin');
$fakeServer->addPlugin($plugin);
$request = new HTTP\Request(array('REQUEST_METHOD' => 'OPTIONS', 'HTTP_DEPTH' => 1, 'REQUEST_URI' => '/adminonly'));
$response = new HTTP\ResponseMock();
$fakeServer->httpRequest = $request;
$fakeServer->httpResponse = $response;
$fakeServer->exec();
$this->assertEquals('HTTP/1.1 200 OK', $response->status);
}
示例12: schedule
function schedule(Message $message)
{
$plugin = new IMip\MockPlugin('system@example.org');
$server = new Server();
$server->addPlugin($plugin);
$server->emit('schedule', [$message]);
return $plugin->getSentEmails();
}
示例13: testGetCurrentUserPrincipal
/**
* @depends testInit
*/
function testGetCurrentUserPrincipal()
{
$fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
$plugin = new Plugin(new Backend\Mock(), 'realm');
$fakeServer->addPlugin($plugin);
$fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]);
$this->assertEquals('admin', $plugin->getCurrentUser());
}
示例14: init
function init()
{
// workaround for HTTP-auth in CGI mode
if (x($_SERVER, 'REDIRECT_REMOTE_USER')) {
$userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"], 6));
if (strlen($userpass)) {
list($name, $password) = explode(':', $userpass);
$_SERVER['PHP_AUTH_USER'] = $name;
$_SERVER['PHP_AUTH_PW'] = $password;
}
}
if (x($_SERVER, 'HTTP_AUTHORIZATION')) {
$userpass = base64_decode(substr($_SERVER["HTTP_AUTHORIZATION"], 6));
if (strlen($userpass)) {
list($name, $password) = explode(':', $userpass);
$_SERVER['PHP_AUTH_USER'] = $name;
$_SERVER['PHP_AUTH_PW'] = $password;
}
}
if (!is_dir('store')) {
os_mkdir('store', STORAGE_DEFAULT_PERMISSIONS, false);
}
if (argc() > 1) {
profile_load(argv(1), 0);
}
$auth = new \Zotlabs\Storage\BasicAuth();
$auth->setRealm(ucfirst(\Zotlabs\Lib\System::get_platform_name()) . ' ' . 'WebDAV');
$rootDirectory = new \Zotlabs\Storage\Directory('/', $auth);
// A SabreDAV server-object
$server = new SDAV\Server($rootDirectory);
$authPlugin = new \Sabre\DAV\Auth\Plugin($auth);
$server->addPlugin($authPlugin);
// prevent overwriting changes each other with a lock backend
$lockBackend = new SDAV\Locks\Backend\File('store/[data]/locks');
$lockPlugin = new SDAV\Locks\Plugin($lockBackend);
$server->addPlugin($lockPlugin);
// provide a directory view for the cloud in Hubzilla
$browser = new \Zotlabs\Storage\Browser($auth);
$auth->setBrowserPlugin($browser);
// Experimental QuotaPlugin
// require_once('Zotlabs/Storage/QuotaPlugin.php');
// $server->addPlugin(new \Zotlabs\Storage\QuotaPlugin($auth));
// All we need to do now, is to fire up the server
$server->exec();
killme();
}
示例15: testGetCurrentUserPrincipal
/**
* @depends testInit
*/
function testGetCurrentUserPrincipal()
{
$fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
$plugin = new Plugin(new Backend\Mock(), 'realm');
$fakeServer->addPlugin($plugin);
$fakeServer->broadCastEvent('beforeMethod', array('GET', '/'));
$this->assertEquals('admin', $plugin->getCurrentUser());
}