本文整理汇总了PHP中OC\Files\Stream\Close::registerCallback方法的典型用法代码示例。如果您正苦于以下问题:PHP Close::registerCallback方法的具体用法?PHP Close::registerCallback怎么用?PHP Close::registerCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Stream\Close
的用法示例。
在下文中一共展示了Close::registerCallback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCloseStream
public function testCloseStream()
{
//ensure all basic stream stuff works
$sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
$tmpFile = \OC::$server->getTempManager()->getTemporaryFile('.txt');
$file = 'close://' . $tmpFile;
$this->assertTrue(file_exists($file));
file_put_contents($file, file_get_contents($sourceFile));
$this->assertEquals(file_get_contents($sourceFile), file_get_contents($file));
unlink($file);
clearstatcache();
$this->assertFalse(file_exists($file));
//test callback
$tmpFile = \OC::$server->getTempManager()->getTemporaryFile('.txt');
$file = 'close://' . $tmpFile;
$actual = false;
$callback = function ($path) use(&$actual) {
$actual = $path;
};
\OC\Files\Stream\Close::registerCallback($tmpFile, $callback);
$fh = fopen($file, 'w');
fwrite($fh, 'asd');
fclose($fh);
$this->assertSame($tmpFile, $actual);
}
示例2: testCloseStream
public function testCloseStream()
{
//ensure all basic stream stuff works
$sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
$tmpFile = OC_Helper::TmpFile('.txt');
$file = 'close://' . $tmpFile;
$this->assertTrue(file_exists($file));
file_put_contents($file, file_get_contents($sourceFile));
$this->assertEquals(file_get_contents($sourceFile), file_get_contents($file));
unlink($file);
clearstatcache();
$this->assertFalse(file_exists($file));
//test callback
$tmpFile = OC_Helper::TmpFile('.txt');
$file = 'close://' . $tmpFile;
\OC\Files\Stream\Close::registerCallback($tmpFile, array('Test_StreamWrappers', 'closeCallBack'));
$fh = fopen($file, 'w');
fwrite($fh, 'asd');
try {
fclose($fh);
$this->fail('Expected exception');
} catch (Exception $e) {
$path = $e->getMessage();
$this->assertEquals($path, $tmpFile);
}
}
示例3: fopen
public function fopen($path, $mode)
{
$path = $this->normalizePath($path);
switch ($mode) {
case 'r':
case 'rb':
try {
$c = $this->getContainer();
$streamFactory = new \Guzzle\Stream\PhpStreamRequestFactory();
$streamInterface = $streamFactory->fromRequest($c->getClient()->get($c->getUrl($path)));
$streamInterface->rewind();
$stream = $streamInterface->getStream();
stream_context_set_option($stream, 'swift', 'content', $streamInterface);
if (!strrpos($streamInterface->getMetaData('wrapper_data')[0], '404 Not Found')) {
return $stream;
}
return false;
} catch (\Guzzle\Http\Exception\BadResponseException $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
return false;
}
case 'w':
case 'wb':
case 'a':
case 'ab':
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
// Fetch existing file if required
if ($mode[0] !== 'w' && $this->file_exists($path)) {
if ($mode[0] === 'x') {
// File cannot already exist
return false;
}
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);
// Seek to end if required
if ($mode[0] === 'a') {
fseek($tmpFile, 0, SEEK_END);
}
}
self::$tmpFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
}
示例4: fopen
public function fopen($path, $mode)
{
$path = $this->normalizePath($path);
switch ($mode) {
case 'r':
case 'rb':
$stat = $this->stat($path);
if (is_array($stat)) {
try {
return $this->objectStore->readObject($this->getURN($stat['fileid']));
} catch (\Exception $ex) {
\OCP\Util::writeLog('objectstore', 'Could not get object: ' . $ex->getMessage(), \OCP\Util::ERROR);
return false;
}
} else {
return false;
}
case 'w':
case 'wb':
case 'a':
case 'ab':
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);
}
self::$tmpFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
return false;
}
示例5: getStream
/**
* get a file handler
*
* @param string $path
* @param string $mode
* @return resource
*/
function getStream($path, $mode)
{
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OCP\Files::tmpFile($ext);
if ($this->fileExists($path)) {
$this->extractFile($path, $tmpFile);
} elseif ($mode == 'r' or $mode == 'rb') {
return false;
}
if ($mode == 'r' or $mode == 'rb') {
return fopen($tmpFile, $mode);
} else {
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
self::$tempFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
}
示例6: fopen
/** {@inheritdoc} */
public function fopen($path, $mode)
{
$this->init();
$path = $this->cleanPath($path);
switch ($mode) {
case 'r':
case 'rb':
try {
$response = $this->httpClientService->newClient()->get($this->createBaseUri() . $this->encodePath($path), ['auth' => [$this->user, $this->password], 'stream' => true]);
} catch (RequestException $e) {
if ($e->getResponse() instanceof ResponseInterface && $e->getResponse()->getStatusCode() === 404) {
return false;
} else {
throw $e;
}
}
if ($response->getStatusCode() !== Http::STATUS_OK) {
if ($response->getStatusCode() === Http::STATUS_LOCKED) {
throw new \OCP\Lock\LockedException($path);
} else {
Util::writeLog("webdav client", 'Guzzle get returned status code ' . $response->getStatusCode(), Util::ERROR);
}
}
return $response->getBody();
case 'w':
case 'wb':
case 'a':
case 'ab':
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
//emulate these
$tempManager = \OC::$server->getTempManager();
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
if ($this->file_exists($path)) {
if (!$this->isUpdatable($path)) {
return false;
}
if ($mode === 'w' or $mode === 'w+') {
$tmpFile = $tempManager->getTemporaryFile($ext);
} else {
$tmpFile = $this->getCachedFile($path);
}
} else {
if (!$this->isCreatable(dirname($path))) {
return false;
}
$tmpFile = $tempManager->getTemporaryFile($ext);
}
Close::registerCallback($tmpFile, array($this, 'writeBack'));
self::$tempFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
}
示例7: fopen
public function fopen($path, $mode)
{
$path = $this->root . $path;
switch ($mode) {
case 'r':
case 'rb':
try {
// slashes need to stay
$encodedPath = str_replace('%2F', '/', rawurlencode(trim($path, '/')));
$downloadUrl = 'https://api-content.dropbox.com/1/files/auto/' . $encodedPath;
$headers = $this->oauth->getOAuthHeader($downloadUrl, [], 'GET');
$client = \OC::$server->getHTTPClientService()->newClient();
try {
$response = $client->get($downloadUrl, ['headers' => $headers, 'stream' => true]);
} catch (RequestException $e) {
if (!is_null($e->getResponse())) {
if ($e->getResponse()->getStatusCode() === 404) {
return false;
} else {
throw $e;
}
} else {
throw $e;
}
}
$handle = $response->getBody();
return RetryWrapper::wrap($handle);
} catch (\Exception $exception) {
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
return false;
}
case 'w':
case 'wb':
case 'a':
case 'ab':
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);
}
self::$tempFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
return false;
}
示例8: fopen
public function fopen($path, $mode)
{
$this->init();
switch ($mode) {
case 'r':
case 'rb':
$obj = $this->getObject($path);
if (is_null($obj)) {
return false;
}
$fp = fopen('php://temp', 'r+');
$obj->stream($fp);
rewind($fp);
return $fp;
case 'w':
case 'wb':
case 'a':
case 'ab':
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
$tmpFile = $this->getTmpFile($path);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
self::$tempFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
}
示例9: fopen
public function fopen($path, $mode)
{
$path = $this->normalizePath($path);
switch ($mode) {
case 'r':
case 'rb':
$tmpFile = \OC_Helper::tmpFile();
self::$tmpFiles[$tmpFile] = $path;
try {
$result = $this->connection->getObject(array('Bucket' => $this->bucket, 'Key' => $this->cleanKey($path), 'SaveAs' => $tmpFile));
} catch (S3Exception $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
return false;
}
return fopen($tmpFile, 'r');
case 'w':
case 'wb':
case 'a':
case 'ab':
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OC_Helper::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);
}
self::$tmpFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
return false;
}
示例10: fopen
public function fopen($path, $mode)
{
switch ($mode) {
case 'r':
case 'rb':
case 'w':
case 'wb':
case 'a':
case 'ab':
//these are supported by the wrapper
$context = stream_context_create(array('ftp' => array('overwrite' => true)));
return fopen($this->constructUrl($path), $mode, false, $context);
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
//emulate these
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$this->getFile($path, $tmpFile);
}
self::$tempFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
return false;
}
示例11: fopen
public function fopen($path, $mode)
{
try {
$absPath = $this->absPath($path);
switch ($mode) {
case 'r':
case 'rb':
if (!$this->file_exists($path)) {
return false;
}
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmp = \OC_Helper::tmpFile($ext);
$this->getFile($absPath, $tmp);
return fopen($tmp, $mode);
case 'w':
case 'wb':
case 'a':
case 'ab':
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OC_Helper::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$this->getFile($absPath, $tmpFile);
}
self::$tempFiles[$tmpFile] = $absPath;
return fopen('close://' . $tmpFile, $mode);
}
} catch (\Exception $e) {
}
return false;
}
示例12: fopen
public function fopen($path, $mode)
{
$this->init();
$path = $this->cleanPath($path);
switch ($mode) {
case 'r':
case 'rb':
if (!$this->file_exists($path)) {
return false;
}
//straight up curl instead of sabredav here, sabredav put's the entire get result in memory
$curl = curl_init();
$fp = fopen('php://temp', 'r+');
curl_setopt($curl, CURLOPT_USERPWD, $this->user . ':' . $this->password);
curl_setopt($curl, CURLOPT_URL, $this->createBaseUri() . str_replace(' ', '%20', $path));
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_exec($curl);
curl_close($curl);
rewind($fp);
return $fp;
case 'w':
case 'wb':
case 'a':
case 'ab':
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
//emulate these
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$this->getFile($path, $tmpFile);
}
self::$tempFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
}
示例13: fopen
public function fopen($path, $mode)
{
$pos = strrpos($path, '.');
if ($pos !== false) {
$ext = substr($path, $pos);
} else {
$ext = '';
}
switch ($mode) {
case 'r':
case 'rb':
$file = $this->getDriveFile($path);
if ($file) {
$exportLinks = $file->getExportLinks();
$mimetype = $this->getMimeType($path);
$downloadUrl = null;
if ($exportLinks && isset($exportLinks[$mimetype])) {
$downloadUrl = $exportLinks[$mimetype];
} else {
$downloadUrl = $file->getDownloadUrl();
}
if (isset($downloadUrl)) {
$request = new \Google_Http_Request($downloadUrl, 'GET', null, null);
$httpRequest = $this->client->getAuth()->sign($request);
// the library's service doesn't support streaming, so we use Guzzle instead
$client = \OC::$server->getHTTPClientService()->newClient();
try {
$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
$client->get($downloadUrl, ['headers' => $httpRequest->getRequestHeaders(), 'save_to' => $tmpFile]);
} catch (RequestException $e) {
if (!is_null($e->getResponse())) {
if ($e->getResponse()->getStatusCode() === 404) {
return false;
} else {
throw $e;
}
} else {
throw $e;
}
}
return fopen($tmpFile, 'r');
}
}
return false;
case 'w':
case 'wb':
case 'a':
case 'ab':
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
$tmpFile = \OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'rb');
file_put_contents($tmpFile, $source);
}
self::$tempFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
}
示例14: getStream
/**
* get a file handler
* @param string $path
* @param string $mode
* @return resource
*/
function getStream($path, $mode)
{
if ($mode == 'r' or $mode == 'rb') {
return $this->zip->getStream($path);
} else {
//since we can't directly get a writable stream,
//make a temp copy of the file and put it back
//in the archive when the stream is closed
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->fileExists($path)) {
$this->extractFile($path, $tmpFile);
}
self::$tempFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
}
示例15: fopen
public function fopen($path, $mode)
{
switch ($mode) {
case 'r':
case 'rb':
$entry = $this->getResource($path);
if ($entry) {
$extension = $this->getExtension($entry);
$downloadUri = $entry->getElementsByTagName('content')->item(0)->getAttribute('src');
// TODO Non-native documents don't need these additional parameters
$downloadUri .= '&exportFormat=' . $extension . '&format=' . $extension;
$tmpFile = $this->sendRequest($downloadUri, 'GET', null, null, true);
return fopen($tmpFile, 'r');
}
case 'w':
case 'wb':
case 'a':
case 'ab':
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OC_Helper::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);
}
self::$tempFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
return false;
}