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


PHP FileBackend类代码示例

本文整理汇总了PHP中FileBackend的典型用法代码示例。如果您正苦于以下问题:PHP FileBackend类的具体用法?PHP FileBackend怎么用?PHP FileBackend使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: stream

 /**
  * Stream a file to the browser, adding all the headings and fun stuff.
  * Headers sent include: Content-type, Content-Length, Last-Modified,
  * and Content-Disposition.
  *
  * @param string $fname Full name and path of the file to stream
  * @param array $headers Any additional headers to send
  * @param bool $sendErrors Send error messages if errors occur (like 404)
  * @throws MWException
  * @return bool Success
  */
 public static function stream($fname, $headers = array(), $sendErrors = true)
 {
     wfProfileIn(__METHOD__);
     if (FileBackend::isStoragePath($fname)) {
         // sanity
         wfProfileOut(__METHOD__);
         throw new MWException(__FUNCTION__ . " given storage path '{$fname}'.");
     }
     wfSuppressWarnings();
     $stat = stat($fname);
     wfRestoreWarnings();
     $res = self::prepareForStream($fname, $stat, $headers, $sendErrors);
     if ($res == self::NOT_MODIFIED) {
         $ok = true;
         // use client cache
     } elseif ($res == self::READY_STREAM) {
         wfProfileIn(__METHOD__ . '-send');
         $ok = readfile($fname);
         wfProfileOut(__METHOD__ . '-send');
     } else {
         $ok = false;
         // failed
     }
     wfProfileOut(__METHOD__);
     return $ok;
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:37,代码来源:StreamFile.php

示例2: assertBackendPathsConsistent

 function assertBackendPathsConsistent(array $paths)
 {
     if ($this->backend instanceof FileBackendMultiWrite) {
         $status = $this->backend->consistencyCheck($paths);
         $this->assertGoodStatus($status, "Files synced: " . implode(',', $paths));
     }
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:7,代码来源:FileBackendTest.php

示例3: __construct

 /**
  * Construct a proxy backend that consists of several internal backends.
  * Additional $config params include:
  *     'backends'    : Array of backend config and multi-backend settings.
  *                     Each value is the config used in the constructor of a
  *                     FileBackendStore class, but with these additional settings:
  *                         'class'         : The name of the backend class
  *                         'isMultiMaster' : This must be set for one backend.
  *     'syncChecks'  : Integer bitfield of internal backend sync checks to perform.
  *                     Possible bits include self::CHECK_SIZE and self::CHECK_TIME.
  *                     The checks are done before allowing any file operations.
  * @param $config Array
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     $namesUsed = array();
     // Construct backends here rather than via registration
     // to keep these backends hidden from outside the proxy.
     foreach ($config['backends'] as $index => $config) {
         $name = $config['name'];
         if (isset($namesUsed[$name])) {
             // don't break FileOp predicates
             throw new MWException("Two or more backends defined with the name {$name}.");
         }
         $namesUsed[$name] = 1;
         if (!isset($config['class'])) {
             throw new MWException('No class given for a backend config.');
         }
         $class = $config['class'];
         $this->backends[$index] = new $class($config);
         if (!empty($config['isMultiMaster'])) {
             if ($this->masterIndex >= 0) {
                 throw new MWException('More than one master backend defined.');
             }
             $this->masterIndex = $index;
         }
     }
     if ($this->masterIndex < 0) {
         // need backends and must have a master
         throw new MWException('No master backend defined.');
     }
     $this->syncChecks = isset($config['syncChecks']) ? $config['syncChecks'] : self::CHECK_SIZE;
 }
开发者ID:amjadtbssm,项目名称:spring-website,代码行数:44,代码来源:FileBackendMultiWrite.php

示例4: __construct

 /**
  * Sets up the file object
  *
  * @param $path string Path to temporary file on local disk
  * @throws MWException
  */
 public function __construct($path)
 {
     if (FileBackend::isStoragePath($path)) {
         throw new MWException(__METHOD__ . " given storage path `{$path}`.");
     }
     $this->path = $path;
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:13,代码来源:FSFile.php

示例5: getPropsFromPath

 /**
  * Get an associative array containing information about
  * a file with the given storage path.
  *
  * Resulting array fields include:
  *   - fileExists
  *   - size (filesize in bytes)
  *   - mime (as major/minor)
  *   - media_type (value to be used with the MEDIATYPE_xxx constants)
  *   - metadata (handler specific)
  *   - sha1 (in base 36)
  *   - width
  *   - height
  *   - bits (bitrate)
  *   - file-mime
  *   - major_mime
  *   - minor_mime
  *
  * @param string $path Filesystem path to a file
  * @param string|bool $ext The file extension, or true to extract it from the filename.
  *             Set it to false to ignore the extension.
  * @return array
  * @since 1.28
  */
 public function getPropsFromPath($path, $ext)
 {
     $fsFile = new FSFile($path);
     $info = $this->newPlaceholderProps();
     $info['fileExists'] = $fsFile->exists();
     if ($info['fileExists']) {
         $info['size'] = $fsFile->getSize();
         // bytes
         $info['sha1'] = $fsFile->getSha1Base36();
         # MIME type according to file contents
         $info['file-mime'] = $this->magic->guessMimeType($path, false);
         # Logical MIME type
         $ext = $ext === true ? FileBackend::extensionFromPath($path) : $ext;
         $info['mime'] = $this->magic->improveTypeFromExtension($info['file-mime'], $ext);
         list($info['major_mime'], $info['minor_mime']) = File::splitMime($info['mime']);
         $info['media_type'] = $this->magic->getMediaType($path, $info['mime']);
         # Height, width and metadata
         $handler = MediaHandler::getHandler($info['mime']);
         if ($handler) {
             $info['metadata'] = $handler->getMetadata($fsFile, $path);
             /** @noinspection PhpMethodParametersCountMismatchInspection */
             $gis = $handler->getImageSize($fsFile, $path, $info['metadata']);
             if (is_array($gis)) {
                 $info = $this->extractImageSizeInfo($gis) + $info;
             }
         }
     }
     return $info;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:53,代码来源:MWFileProps.php

示例6: __construct

 /**
  * @see FileBackend::__construct()
  *
  * @param $config Array
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     $this->memCache = new EmptyBagOStuff();
     // disabled by default
     $this->cheapCache = new ProcessCacheLRU(300);
     $this->expensiveCache = new ProcessCacheLRU(5);
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:13,代码来源:FileBackendStore.php

示例7: stream

 /**
  * Stream a file to the browser, adding all the headings and fun stuff.
  * Headers sent include: Content-type, Content-Length, Last-Modified,
  * and Content-Disposition.
  *
  * @param string $fname Full name and path of the file to stream
  * @param array $headers Any additional headers to send if the file exists
  * @param bool $sendErrors Send error messages if errors occur (like 404)
  * @param array $optHeaders HTTP request header map (e.g. "range") (use lowercase keys)
  * @param integer $flags Bitfield of STREAM_* constants
  * @throws MWException
  * @return bool Success
  */
 public static function stream($fname, $headers = [], $sendErrors = true, $optHeaders = [], $flags = 0)
 {
     if (FileBackend::isStoragePath($fname)) {
         // sanity
         throw new InvalidArgumentException(__FUNCTION__ . " given storage path '{$fname}'.");
     }
     $streamer = new HTTPFileStreamer($fname, ['obResetFunc' => 'wfResetOutputBuffers', 'streamMimeFunc' => [__CLASS__, 'contentTypeFromPath']]);
     return $streamer->stream($headers, $sendErrors, $optHeaders, $flags);
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:22,代码来源:StreamFile.php

示例8: tearDown

 protected function tearDown()
 {
     $this->repo->cleanupBatch($this->createdFiles);
     // delete files
     foreach ($this->createdFiles as $tmp) {
         // delete dirs
         $tmp = $this->repo->resolveVirtualUrl($tmp);
         while ($tmp = FileBackend::parentStoragePath($tmp)) {
             $this->repo->getBackend()->clean(array('dir' => $tmp));
         }
     }
     parent::tearDown();
 }
开发者ID:nischayn22,项目名称:mediawiki-core,代码行数:13,代码来源:StoreBatchTest.php

示例9: stream

 /**
  * Stream a file to the browser, adding all the headings and fun stuff.
  * Headers sent include: Content-type, Content-Length, Last-Modified,
  * and Content-Disposition.
  *
  * @param string $fname Full name and path of the file to stream
  * @param array $headers Any additional headers to send
  * @param bool $sendErrors Send error messages if errors occur (like 404)
  * @throws MWException
  * @return bool Success
  */
 public static function stream($fname, $headers = [], $sendErrors = true)
 {
     if (FileBackend::isStoragePath($fname)) {
         // sanity
         throw new MWException(__FUNCTION__ . " given storage path '{$fname}'.");
     }
     MediaWiki\suppressWarnings();
     $stat = stat($fname);
     MediaWiki\restoreWarnings();
     $res = self::prepareForStream($fname, $stat, $headers, $sendErrors);
     if ($res == self::NOT_MODIFIED) {
         $ok = true;
         // use client cache
     } elseif ($res == self::READY_STREAM) {
         $ok = readfile($fname);
     } else {
         $ok = false;
         // failed
     }
     return $ok;
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:32,代码来源:StreamFile.php

示例10: execute

 public function execute()
 {
     $out = $this->mSpecial->getOutput();
     $dbr = wfGetDB(DB_SLAVE);
     $row = $dbr->selectRow('moderation', array('mod_user AS user', 'mod_user_text AS user_text', 'mod_title AS title', 'mod_stash_key AS stash_key'), array('mod_id' => $this->id), __METHOD__);
     if (!$row) {
         throw new ModerationError('moderation-edit-not-found');
     }
     $user = $row->user ? User::newFromId($row->user) : User::newFromName($row->user_text, false);
     $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash($user);
     try {
         $file = $stash->getFile($row->stash_key);
     } catch (MWException $e) {
         return $this->send404ImageNotFound();
     }
     $is_thumb = $this->mSpecial->getRequest()->getVal('thumb');
     if ($is_thumb) {
         $thumb = $file->transform(array('width' => self::THUMB_WIDTH), File::RENDER_NOW);
         if ($thumb) {
             if ($thumb->fileIsSource()) {
                 $is_thumb = false;
             } else {
                 $file = new UnregisteredLocalFile(false, $stash->repo, $thumb->getStoragePath(), false);
             }
         }
     }
     if (!$file) {
         return $this->send404ImageNotFound();
     }
     $thumb_filename = '';
     if ($is_thumb) {
         $thumb_filename .= $file->getWidth() . 'px-';
     }
     $thumb_filename .= $row->title;
     $headers = array();
     $headers[] = "Content-Disposition: " . FileBackend::makeContentDisposition('inline', $thumb_filename);
     $out->disable();
     # No HTML output (image only)
     $file->getRepo()->streamFile($file->getPath(), $headers);
 }
开发者ID:ATCARES,项目名称:mediawiki-moderation,代码行数:40,代码来源:ModerationActionShowImage.php

示例11: fileExistsBatch

 /**
  * @param array $files
  * @return array
  */
 function fileExistsBatch(array $files)
 {
     $results = [];
     foreach ($files as $k => $f) {
         if (isset($this->mFileExists[$f])) {
             $results[$k] = $this->mFileExists[$f];
             unset($files[$k]);
         } elseif (self::isVirtualUrl($f)) {
             # @todo FIXME: We need to be able to handle virtual
             # URLs better, at least when we know they refer to the
             # same repo.
             $results[$k] = false;
             unset($files[$k]);
         } elseif (FileBackend::isStoragePath($f)) {
             $results[$k] = false;
             unset($files[$k]);
             wfWarn("Got mwstore:// path '{$f}'.");
         }
     }
     $data = $this->fetchImageQuery(['titles' => implode($files, '|'), 'prop' => 'imageinfo']);
     if (isset($data['query']['pages'])) {
         # First, get results from the query. Note we only care whether the image exists,
         # not whether it has a description page.
         foreach ($data['query']['pages'] as $p) {
             $this->mFileExists[$p['title']] = $p['imagerepository'] !== '';
         }
         # Second, copy the results to any redirects that were queried
         if (isset($data['query']['redirects'])) {
             foreach ($data['query']['redirects'] as $r) {
                 $this->mFileExists[$r['from']] = $this->mFileExists[$r['to']];
             }
         }
         # Third, copy the results to any non-normalized titles that were queried
         if (isset($data['query']['normalized'])) {
             foreach ($data['query']['normalized'] as $n) {
                 $this->mFileExists[$n['from']] = $this->mFileExists[$n['to']];
             }
         }
         # Finally, copy the results to the output
         foreach ($files as $key => $file) {
             $results[$key] = $this->mFileExists[$file];
         }
     }
     return $results;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:49,代码来源:ForeignAPIRepo.php

示例12: upload

 /**
  * Upload a file and record it in the DB
  * @param string $srcPath Source storage path, virtual URL, or filesystem path
  * @param string $comment Upload description
  * @param string $pageText Text to use for the new description page,
  *   if a new description page is created
  * @param int|bool $flags Flags for publish()
  * @param array|bool $props File properties, if known. This can be used to
  *   reduce the upload time when uploading virtual URLs for which the file
  *   info is already known
  * @param string|bool $timestamp Timestamp for img_timestamp, or false to use the
  *   current time
  * @param User|null $user User object or null to use $wgUser
  * @param string[] $tags Change tags to add to the log entry and page revision.
  *   (This doesn't check $user's permissions.)
  * @return FileRepoStatus On success, the value member contains the
  *     archive name, or an empty string if it was a new file.
  */
 function upload($srcPath, $comment, $pageText, $flags = 0, $props = false, $timestamp = false, $user = null, $tags = array())
 {
     global $wgContLang;
     if ($this->getRepo()->getReadOnlyReason() !== false) {
         return $this->readOnlyFatalStatus();
     }
     if (!$props) {
         if ($this->repo->isVirtualUrl($srcPath) || FileBackend::isStoragePath($srcPath)) {
             $props = $this->repo->getFileProps($srcPath);
         } else {
             $props = FSFile::getPropsFromPath($srcPath);
         }
     }
     $options = array();
     $handler = MediaHandler::getHandler($props['mime']);
     if ($handler) {
         $options['headers'] = $handler->getStreamHeaders($props['metadata']);
     } else {
         $options['headers'] = array();
     }
     // Trim spaces on user supplied text
     $comment = trim($comment);
     // Truncate nicely or the DB will do it for us
     // non-nicely (dangling multi-byte chars, non-truncated version in cache).
     $comment = $wgContLang->truncate($comment, 255);
     $this->lock();
     // begin
     $status = $this->publish($srcPath, $flags, $options);
     if ($status->successCount >= 2) {
         // There will be a copy+(one of move,copy,store).
         // The first succeeding does not commit us to updating the DB
         // since it simply copied the current version to a timestamped file name.
         // It is only *preferable* to avoid leaving such files orphaned.
         // Once the second operation goes through, then the current version was
         // updated and we must therefore update the DB too.
         $oldver = $status->value;
         if (!$this->recordUpload2($oldver, $comment, $pageText, $props, $timestamp, $user, $tags)) {
             $status->fatal('filenotfound', $srcPath);
         }
     }
     $this->unlock();
     // done
     return $status;
 }
开发者ID:paladox,项目名称:2,代码行数:62,代码来源:LocalFile.php

示例13: wfMkdirParents

/**
 * Make directory, and make all parent directories if they don't exist
 *
 * @param string $dir Full path to directory to create
 * @param int $mode Chmod value to use, default is $wgDirectoryMode
 * @param string $caller Optional caller param for debugging.
 * @throws MWException
 * @return bool
 */
function wfMkdirParents($dir, $mode = null, $caller = null)
{
    global $wgDirectoryMode;
    if (FileBackend::isStoragePath($dir)) {
        // sanity
        throw new MWException(__FUNCTION__ . " given storage path '{$dir}'.");
    }
    if (!is_null($caller)) {
        wfDebug("{$caller}: called wfMkdirParents({$dir})\n");
    }
    if (strval($dir) === '' || is_dir($dir)) {
        return true;
    }
    $dir = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $dir);
    if (is_null($mode)) {
        $mode = $wgDirectoryMode;
    }
    // Turn off the normal warning, we're doing our own below
    MediaWiki\suppressWarnings();
    $ok = mkdir($dir, $mode, true);
    // PHP5 <3
    MediaWiki\restoreWarnings();
    if (!$ok) {
        //directory may have been created on another request since we last checked
        if (is_dir($dir)) {
            return true;
        }
        // PHP doesn't report the path in its warning message, so add our own to aid in diagnosis.
        wfLogWarning(sprintf("failed to mkdir \"%s\" mode 0%o", $dir, $mode));
    }
    return $ok;
}
开发者ID:D66Ha,项目名称:mediawiki,代码行数:41,代码来源:GlobalFunctions.php

示例14: testExtensionFromPath

 /**
  * @dataProvider provider_testExtensionFromPath
  */
 public function testExtensionFromPath($path, $res)
 {
     $this->assertEquals($res, FileBackend::extensionFromPath($path), "FileBackend::extensionFromPath on path '{$path}'");
 }
开发者ID:nischayn22,项目名称:mediawiki-core,代码行数:7,代码来源:FileBackendTest.php

示例15: filesAreSame

 protected function filesAreSame(FileBackend $src, FileBackend $dst, $sPath, $dPath)
 {
     return $src->getFileSize(['src' => $sPath]) === $dst->getFileSize(['src' => $dPath]) && $src->getFileSha1Base36(['src' => $sPath]) === $dst->getFileSha1Base36(['src' => $dPath]);
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:4,代码来源:syncFileBackend.php


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