当前位置: 首页>>代码示例>>PHP>>正文


PHP Cache::searchByTag方法代码示例

本文整理汇总了PHP中OC\Files\Cache\Cache::searchByTag方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::searchByTag方法的具体用法?PHP Cache::searchByTag怎么用?PHP Cache::searchByTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OC\Files\Cache\Cache的用法示例。


在下文中一共展示了Cache::searchByTag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSearchByTag

	function testSearchByTag() {
		$userId = $this->getUniqueId('user');
		\OC_User::createUser($userId, $userId);
		$this->loginAsUser($userId);
		$user = new \OC\User\User($userId, null);

		$file1 = 'folder';
		$file2 = 'folder/foobar';
		$file3 = 'folder/foo';
		$file4 = 'folder/foo2';
		$file5 = 'folder/foo3';
		$data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
		$fileData = array();
		$fileData['foobar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
		$fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file');
		$fileData['foo2'] = array('size' => 25, 'mtime' => 28, 'mimetype' => 'foo/file');
		$fileData['foo3'] = array('size' => 88, 'mtime' => 34, 'mimetype' => 'foo/file');

		$id1 = $this->cache->put($file1, $data1);
		$id2 = $this->cache->put($file2, $fileData['foobar']);
		$id3 = $this->cache->put($file3, $fileData['foo']);
		$id4 = $this->cache->put($file4, $fileData['foo2']);
		$id5 = $this->cache->put($file5, $fileData['foo3']);

		$tagManager = \OC::$server->getTagManager()->load('files', null, null, $userId);
		$this->assertTrue($tagManager->tagAs($id1, 'tag1'));
		$this->assertTrue($tagManager->tagAs($id1, 'tag2'));
		$this->assertTrue($tagManager->tagAs($id2, 'tag2'));
		$this->assertTrue($tagManager->tagAs($id3, 'tag1'));
		$this->assertTrue($tagManager->tagAs($id4, 'tag2'));

		// use tag name
		$results = $this->cache->searchByTag('tag1', $userId);

		$this->assertEquals(2, count($results));

		usort($results, function($value1, $value2) { return $value1['name'] >= $value2['name']; });

		$this->assertEquals('folder', $results[0]['name']);
		$this->assertEquals('foo', $results[1]['name']);

		// use tag id
		$tags = $tagManager->getTagsForUser($userId);
		$this->assertNotEmpty($tags);
		$tags = array_filter($tags, function($tag) { return $tag->getName() === 'tag2'; });
		$results = $this->cache->searchByTag(current($tags)->getId(), $userId);
		$this->assertEquals(3, count($results));

		usort($results, function($value1, $value2) { return $value1['name'] >= $value2['name']; });

		$this->assertEquals('folder', $results[0]['name']);
		$this->assertEquals('foo2', $results[1]['name']);
		$this->assertEquals('foobar', $results[2]['name']);

		$tagManager->delete('tag1');
		$tagManager->delete('tag2');

		$this->logout();
		\OC_User::deleteUser($userId);
	}
开发者ID:ninjasilicon,项目名称:core,代码行数:60,代码来源:cache.php

示例2: searchByTag

 /**
  * search for files by tag
  *
  * @param string|int $tag name or tag id
  * @param string $userId owner of the tags
  * @return array file data
  */
 public function searchByTag($tag, $userId)
 {
     $results = $this->cache->searchByTag($tag, $userId);
     return array_map(array($this, 'formatCacheEntry'), $results);
 }
开发者ID:kebenxiaoming,项目名称:owncloudRedis,代码行数:12,代码来源:cachewrapper.php


注:本文中的OC\Files\Cache\Cache::searchByTag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。