本文整理汇总了PHP中FileBackend::concatenate方法的典型用法代码示例。如果您正苦于以下问题:PHP FileBackend::concatenate方法的具体用法?PHP FileBackend::concatenate怎么用?PHP FileBackend::concatenate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileBackend
的用法示例。
在下文中一共展示了FileBackend::concatenate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: concatenate
/**
* Concatenate a list of temporary files into a target file location.
*
* @param array $srcPaths Ordered list of source virtual URLs/storage paths
* @param string $dstPath Target file system path
* @param int $flags Bitwise combination of the following flags:
* self::DELETE_SOURCE Delete the source files
* @return FileRepoStatus
*/
public function concatenate(array $srcPaths, $dstPath, $flags = 0)
{
$this->assertWritableRepo();
// fail out if read-only
$status = $this->newGood();
$sources = array();
foreach ($srcPaths as $srcPath) {
// Resolve source to a storage path if virtual
$source = $this->resolveToStoragePath($srcPath);
$sources[] = $source;
// chunk to merge
}
// Concatenate the chunks into one FS file
$params = array('srcs' => $sources, 'dst' => $dstPath);
$status->merge($this->backend->concatenate($params));
if (!$status->isOK()) {
return $status;
}
// Delete the sources if required
if ($flags & self::DELETE_SOURCE) {
$status->merge($this->quickPurgeBatch($srcPaths));
}
// Make sure status is OK, despite any quickPurgeBatch() fatals
$status->setResult(true);
return $status;
}
示例2: concatenate
/**
* Concatenate a list of files into a target file location.
*
* @param $srcPaths Array Ordered list of source virtual URLs/storage paths
* @param $dstPath String Target file system path
* @param $flags Integer: bitwise combination of the following flags:
* self::DELETE_SOURCE Delete the source files
* @return FileRepoStatus
*/
function concatenate($srcPaths, $dstPath, $flags = 0)
{
$status = $this->newGood();
$sources = array();
$deleteOperations = array();
// post-concatenate ops
foreach ($srcPaths as $srcPath) {
// Resolve source to a storage path if virtual
$source = $this->resolveToStoragePath($srcPath);
$sources[] = $source;
// chunk to merge
if ($flags & self::DELETE_SOURCE) {
$deleteOperations[] = array('op' => 'delete', 'src' => $source);
}
}
// Concatenate the chunks into one FS file
$params = array('srcs' => $sources, 'dst' => $dstPath);
$status->merge($this->backend->concatenate($params));
if (!$status->isOK()) {
return $status;
}
// Delete the sources if required
if ($deleteOperations) {
$opts = array('force' => true);
$status->merge($this->backend->doOperations($deleteOperations, $opts));
}
// Make sure status is OK, despite any $deleteOperations fatals
$status->setResult(true);
return $status;
}
示例3: doTestConcatenate
private function doTestConcatenate($params, $srcs, $srcsContent, $alreadyExists, $okStatus)
{
$backendName = $this->backendClass();
$expContent = '';
// Create sources
$ops = array();
foreach ($srcs as $i => $source) {
$this->prepare(array('dir' => dirname($source)));
$ops[] = array('op' => 'create', 'dst' => $source, 'content' => $srcsContent[$i]);
$expContent .= $srcsContent[$i];
}
$status = $this->backend->doOperations($ops);
$this->assertGoodStatus($status, "Creation of source files succeeded ({$backendName}).");
$dest = $params['dst'];
if ($alreadyExists) {
$ok = file_put_contents($dest, 'blah...blah...waahwaah') !== false;
$this->assertEquals(true, $ok, "Creation of file at {$dest} succeeded ({$backendName}).");
} else {
$ok = file_put_contents($dest, '') !== false;
$this->assertEquals(true, $ok, "Creation of 0-byte file at {$dest} succeeded ({$backendName}).");
}
// Combine the files into one
$status = $this->backend->concatenate($params);
if ($okStatus) {
$this->assertGoodStatus($status, "Creation of concat file at {$dest} succeeded without warnings ({$backendName}).");
$this->assertEquals(true, $status->isOK(), "Creation of concat file at {$dest} succeeded ({$backendName}).");
} else {
$this->assertEquals(false, $status->isOK(), "Creation of concat file at {$dest} failed ({$backendName}).");
}
if ($okStatus) {
$this->assertEquals(true, is_file($dest), "Dest concat file {$dest} exists after creation ({$backendName}).");
} else {
$this->assertEquals(true, is_file($dest), "Dest concat file {$dest} exists after failed creation ({$backendName}).");
}
$contents = file_get_contents($dest);
$this->assertNotEquals(false, $contents, "File at {$dest} exists ({$backendName}).");
if ($okStatus) {
$this->assertEquals($expContent, $contents, "Concat file at {$dest} has correct contents ({$backendName}).");
} else {
$this->assertNotEquals($expContent, $contents, "Concat file at {$dest} has correct contents ({$backendName}).");
}
}