syren7/owncloud-api-bundle

本捆绑包允许您通过配置API管理owncloud用户,并通过sabre dav管理文件。

安装: 957

依赖: 0

建议者: 0

安全: 0

星标: 6

关注者: 4

分支: 4

开放问题: 3

类型:symfony-bundle

1.3.5 2018-04-03 12:56 UTC

This package is not auto-updated.

Last update: 2024-09-15 22:59:28 UTC


README

这个ownCloud API捆绑包允许您访问ownCloud的用户、组、共享、文件和日历。目前只有部分完整功能可用,但我将尝试实现每个功能。如果您有任何问题、问题或想参与项目,请留下评论或发送电子邮件

安装

步骤 1:下载捆绑包

打开命令行,进入您的项目目录,然后执行以下命令以下载此捆绑包的最新稳定版本

$ composer require syren7/owncloud-api-bundle

此命令要求您全局安装Composer,如Composer文档中的安装章节中所述。

步骤 2:启用捆绑包

然后,通过将其添加到项目app/AppKernel.php文件中注册的捆绑包列表中,启用捆绑包

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel {
    public function registerBundles() {
        $bundles = array(
            // ...

            new Syren7\OwncloudApiBundle\Syren7OwncloudApiBundle(),
        );

        // ...
    }

    // ...
}

步骤 3:配置捆绑包

现在,您需要配置此捆绑包的参数。

重要:请确保您使用https进行加密,因为密码将以明文形式传输

    // app/config/config.yml
    // YOU SHOULD NOT SET SENSITIVE DATA HERE!
    syren7_owncloud:
        host: '%owncloud_host%'
        user: '%owncloud_user%'
        pass: '%owncloud_pass%'
        folder: '%owncloud_folder%' #NOTE: this setting is optional
    // app/config/parameters.yml
    owncloud_host: 'UrlToYouOwncloudServer' #e.g. https://cloud.yourhost.com/ or https://yourhost.com/owncloud/
    owncloud_user: 'YourOwncloudUsername' #if you want to access user specific functions (like adding and removeing), make sure your owncloud user has enough rights
    owncloud_pass: 'YourOwncloudPassword'
    owncloud_folder: 'RootFolderForStoringFiles' # You can add here some folder where you want to store your files. Leave empty if you want to user the users root directory

注意owncloud_folder参数。如果您将其留空,捆绑包将始终使用在owncloud_user中提供的用户的家庭(或根)目录。如果您想在用户的子文件夹中存储数据,请在owncloud_folder中设置它,相对于用户的主目录!
例如,您在鲍勃的主目录中有一个名为bob的文件的文件夹,并且您想将捆绑包创建的所有文件存储在此目录中,请将owncloud_folder设置为owncloud_folder: "bob的文件/"

如示例中所述(文件系统示例
如果您使用不带参数的getDirectoryContents()扫描目录,捆绑包现在将扫描bob的文件/而不是鲍勃的主目录。

步骤 4:使用捆绑包

现在,您有三种服务可以联系owncloud服务器。syren7_owncloud.filesystem用于访问WebDav服务,syren7_owncloud.user用于管理您的owncloud实例上的用户、组和子管理员。

 // in some controller file you can do the following
 $this->get('syren7_owncloud.filesystem'); //using filesystem tools on owncloud
 $this->get('syren7_owncloud.user'); //managing users and groups
 $this->get('syren7_owncloud.calendar'); //reading calendars and events

调试

出于调试目的,您可以调用服务中的getLastRequest()方法。它将返回来自您的ownCloud服务器的响应。这样您就可以看到与ownCloud API文档相对应的错误类型。

#Example of an response from server

示例

您可以在docs/文件夹中查看其他示例和进一步文档。

文件系统示例

如果您想在不使用symfony的情况下使用此API,可以按照以下示例进行操作

//Basic example for the filesystem api  
  
//edit the following line, if you have your vendors not installed to vendor/ Folder  
require_once 'vendor/autoload.php';  
//create a new object with your owncloud credentials  
$fs = new \Syren7\OwncloudApiBundle\Service\OwncloudFilesystem('YourHostNameHere', 'YourOcUserName', 'YourOcPassword', 'LeaveBlankIfYouWantToWriteIntoUsersRootDirectory');  
  
//do your operations as you would do in symfony  
//List all files and directories (optional give a subdirectory as parameter)  
$fs->getDirectoryContents('Optional:YourPathToADirectory');
  
//returns a file handle from Oc. Filname as parameter  
$file = $fs->getFile('Path/To/File.txt');
//write file to local filesystem
file_put_contents('Path/To/New/Local/File.txt', $file->read());

//create a directory  
$fs->createDirectory('Path/To/New/Directory/On/Your/Oc');
  
//remove a directory  
$fs->removeDirectory('Path/To/Remove/Directory/On/Your/Oc');
  
//uploads a file to your oc  
$fs->createFile('Local/Path/To/File.txt', 'Optional: Remote/Path/To/File');
  
//removes a file from your oc  
$fs->removeFile($path='');  

//rename a file on your cloud ($file is the file returned by $fs->getFile())
$fs->renameFile(File $file, 'newFileName.txt');

//copy a file on your cloud ($file is the file returned by $fs->getFile())
$fs->copyFile(File $file, 'newFileName.txt');
  

开发

此捆绑包仍在开发中,如果您想参与,请告诉我!您也可以写一封电子邮件

捐赠

这是一个完全免费的项目,您可以在任何地方使用它。如果您喜欢此捆绑包并想捐赠一些“咖啡”,请随时在PayPal上这样做