コード例 #1
0
ファイル: FileTest.php プロジェクト: rene-s/Seafile-PHP-SDK
 /**
  * Test create() with valid DirectoryItem
  *
  * @return void
  */
 public function testCreate()
 {
     $clientMock = $this->getMockedClient(new Response(201, ['Content-Type' => 'application/json'], 'success'));
     $clientMock->expects(self::any())->method('request')->with(self::equalTo('POST'), 'http://example.com/index.html/repos/123/file/?p=/some_name.txt')->will(self::returnValue(new Response(201, ['Content-Type' => 'application/json'], 'success')));
     $fileResource = new File($clientMock);
     $lib = new Library();
     $lib->id = 123;
     $dirItem = new DirectoryItem();
     $dirItem->path = '/';
     $dirItem->name = 'some_name.txt';
     self::assertTrue($fileResource->create($lib, $dirItem));
 }
コード例 #2
0
 *   "baseUri": "https://your.seafile-server.example.com",
 *   "testLibId": "ID of an encrypted library",
 *   "testLibPassword": "******"
 * }
 */
$cfgFile = getenv("HOME") . "/.seafile-php-sdk/cfg.json";
if (!is_readable($tokenFile)) {
    throw new Exception($tokenFile . ' is not readable or does not exist.');
}
if (!is_readable($cfgFile)) {
    throw new Exception($cfgFile . ' is not readable or does not exist.');
}
$token = json_decode(file_get_contents($tokenFile));
$cfg = json_decode(file_get_contents($cfgFile));
$client = new Client(['base_uri' => $cfg->baseUri, 'debug' => true, 'handler' => $stack, 'headers' => ['Content-Type' => 'application/json', 'Authorization' => 'Token ' . $token->token]]);
$libraryResource = new Library($client);
$fileResource = new File($client);
$libId = $cfg->testLibId;
$lib = $libraryResource->getById($libId);
if ($lib->encrypted === true && isset($cfg->testLibPassword)) {
    $success = $libraryResource->decrypt($libId, ['query' => ['password' => $cfg->testLibPassword]]);
}
$logger->log(Logger::INFO, "#################### Create empty file on Seafile server.");
$dirItem = (new DirectoryItem())->fromArray(['path' => '/', 'name' => uniqid('some_name_', true) . '.txt']);
$success = $fileResource->create($lib, $dirItem);
if ($success === true) {
    $logger->log(Logger::INFO, "#################### File created: " . $dirItem->name);
} else {
    $logger->log(Logger::ERROR, "#################### File created: " . $dirItem->name);
}
print PHP_EOL . 'Done' . PHP_EOL;