本文整理汇总了PHP中FileRepo::fileExists方法的典型用法代码示例。如果您正苦于以下问题:PHP FileRepo::fileExists方法的具体用法?PHP FileRepo::fileExists怎么用?PHP FileRepo::fileExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileRepo
的用法示例。
在下文中一共展示了FileRepo::fileExists方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* Transform a media file
*
* @param array $params an associative array of handler-specific parameters.
* Typical keys are width, height and page.
* @param $flags Integer: a bitfield, may contain self::RENDER_NOW to force rendering
* @return MediaTransformOutput|bool False on failure
*/
function transform($params, $flags = 0)
{
global $wgUseSquid, $wgIgnoreImageErrors, $wgThumbnailEpoch;
wfProfileIn(__METHOD__);
do {
if (!$this->canRender()) {
$thumb = $this->iconThumb();
break;
// not a bitmap or renderable image, don't try
}
// Get the descriptionUrl to embed it as comment into the thumbnail. Bug 19791.
$descriptionUrl = $this->getDescriptionUrl();
if ($descriptionUrl) {
$params['descriptionUrl'] = wfExpandUrl($descriptionUrl, PROTO_CANONICAL);
}
$handler = $this->getHandler();
$script = $this->getTransformScript();
if ($script && !($flags & self::RENDER_NOW)) {
// Use a script to transform on client request, if possible
$thumb = $handler->getScriptedTransform($this, $script, $params);
if ($thumb) {
break;
}
}
$normalisedParams = $params;
$handler->normaliseParams($this, $normalisedParams);
$thumbName = $this->thumbName($normalisedParams);
$thumbUrl = $this->getThumbUrl($thumbName);
$thumbPath = $this->getThumbPath($thumbName);
// final thumb path
if ($this->repo) {
// Defer rendering if a 404 handler is set up...
if ($this->repo->canTransformVia404() && !($flags & self::RENDER_NOW)) {
wfDebug(__METHOD__ . " transformation deferred.");
// XXX: Pass in the storage path even though we are not rendering anything
// and the path is supposed to be an FS path. This is due to getScalerType()
// getting called on the path and clobbering $thumb->getUrl() if it's false.
$thumb = $handler->getTransform($this, $thumbPath, $thumbUrl, $params);
break;
}
// Clean up broken thumbnails as needed
$this->migrateThumbFile($thumbName);
// Check if an up-to-date thumbnail already exists...
wfDebug(__METHOD__ . ": Doing stat for {$thumbPath}\n");
if (!($flags & self::RENDER_FORCE) && $this->repo->fileExists($thumbPath)) {
$timestamp = $this->repo->getFileTimestamp($thumbPath);
if ($timestamp !== false && $timestamp >= $wgThumbnailEpoch) {
// XXX: Pass in the storage path even though we are not rendering anything
// and the path is supposed to be an FS path. This is due to getScalerType()
// getting called on the path and clobbering $thumb->getUrl() if it's false.
$thumb = $handler->getTransform($this, $thumbPath, $thumbUrl, $params);
$thumb->setStoragePath($thumbPath);
break;
}
} elseif ($flags & self::RENDER_FORCE) {
wfDebug(__METHOD__ . " forcing rendering per flag File::RENDER_FORCE\n");
}
}
// If the backend is ready-only, don't keep generating thumbnails
// only to return transformation errors, just return the error now.
if ($this->repo->getReadOnlyReason() !== false) {
$thumb = $this->transformErrorOutput($thumbPath, $thumbUrl, $params, $flags);
break;
}
// Create a temp FS file with the same extension and the thumbnail
$thumbExt = FileBackend::extensionFromPath($thumbPath);
$tmpFile = TempFSFile::factory('transform_', $thumbExt);
if (!$tmpFile) {
$thumb = $this->transformErrorOutput($thumbPath, $thumbUrl, $params, $flags);
break;
}
$tmpThumbPath = $tmpFile->getPath();
// path of 0-byte temp file
// Actually render the thumbnail...
wfProfileIn(__METHOD__ . '-doTransform');
$thumb = $handler->doTransform($this, $tmpThumbPath, $thumbUrl, $params);
wfProfileOut(__METHOD__ . '-doTransform');
$tmpFile->bind($thumb);
// keep alive with $thumb
if (!$thumb) {
// bad params?
$thumb = null;
} elseif ($thumb->isError()) {
// transform error
$this->lastError = $thumb->toText();
// Ignore errors if requested
if ($wgIgnoreImageErrors && !($flags & self::RENDER_NOW)) {
$thumb = $handler->getTransform($this, $tmpThumbPath, $thumbUrl, $params);
}
} elseif ($this->repo && $thumb->hasFile() && !$thumb->fileIsSource()) {
// Copy the thumbnail from the file system into storage...
$disposition = $this->getThumbDisposition($thumbName);
//.........这里部分代码省略.........
示例2: __construct
/**
* A LocalFile wrapper around a file that has been temporarily stashed,
* so we can do things like create thumbnails for it. Arguably
* UnregisteredLocalFile should be handling its own file repo but that
* class is a bit retarded currently.
*
* @param FileRepo $repo Repository where we should find the path
* @param string $path Path to file
* @param string $key Key to store the path and any stashed data under
* @throws UploadStashBadPathException
* @throws UploadStashFileNotFoundException
*/
public function __construct($repo, $path, $key)
{
$this->fileKey = $key;
// resolve mwrepo:// urls
if ($repo->isVirtualUrl($path)) {
$path = $repo->resolveVirtualUrl($path);
} else {
// check if path appears to be sane, no parent traversals,
// and is in this repo's temp zone.
$repoTempPath = $repo->getZonePath('temp');
if (!$repo->validateFilename($path) || strpos($path, $repoTempPath) !== 0) {
wfDebug("UploadStash: tried to construct an UploadStashFile " . "from a file that should already exist at '{$path}', but path is not valid\n");
throw new UploadStashBadPathException('path is not valid');
}
// check if path exists! and is a plain file.
if (!$repo->fileExists($path)) {
wfDebug("UploadStash: tried to construct an UploadStashFile from " . "a file that should already exist at '{$path}', but path is not found\n");
throw new UploadStashFileNotFoundException('cannot find path, or not a plain file');
}
}
parent::__construct(false, $repo, $path, false);
$this->name = basename($this->path);
}
示例3: getThumbnailSource
/**
* Returns the most appropriate source image for the thumbnail, given a target thumbnail size
* @param array $params
* @return array Source path and width/height of the source
*/
public function getThumbnailSource($params)
{
if ($this->repo && $this->getHandler()->supportsBucketing() && isset($params['physicalWidth']) && ($bucket = $this->getThumbnailBucket($params['physicalWidth']))) {
if ($this->getWidth() != 0) {
$bucketHeight = round($this->getHeight() * ($bucket / $this->getWidth()));
} else {
$bucketHeight = 0;
}
// Try to avoid reading from storage if the file was generated by this script
if (isset($this->tmpBucketedThumbCache[$bucket])) {
$tmpPath = $this->tmpBucketedThumbCache[$bucket];
if (file_exists($tmpPath)) {
return array('path' => $tmpPath, 'width' => $bucket, 'height' => $bucketHeight);
}
}
$bucketPath = $this->getBucketThumbPath($bucket);
if ($this->repo->fileExists($bucketPath)) {
$fsFile = $this->repo->getLocalReference($bucketPath);
if ($fsFile) {
return array('path' => $fsFile->getPath(), 'width' => $bucket, 'height' => $bucketHeight);
}
}
}
// Thumbnailing a very large file could result in network saturation if
// everyone does it at once.
if ($this->getSize() >= 10000000.0) {
// 10MB
$that = $this;
$work = new PoolCounterWorkViaCallback('GetLocalFileCopy', sha1($this->getName()), array('doWork' => function () use($that) {
return $that->getLocalRefPath();
}));
$srcPath = $work->execute();
} else {
$srcPath = $this->getLocalRefPath();
}
// Original file
return array('path' => $srcPath, 'width' => $this->getWidth(), 'height' => $this->getHeight());
}
示例4: getThumbnailSource
/**
* Returns the most appropriate source image for the thumbnail, given a target thumbnail size
* @param array $params
* @return array Source path and width/height of the source
*/
public function getThumbnailSource($params)
{
if ($this->repo && $this->getHandler()->supportsBucketing() && isset($params['physicalWidth']) && ($bucket = $this->getThumbnailBucket($params['physicalWidth']))) {
if ($this->getWidth() != 0) {
$bucketHeight = round($this->getHeight() * ($bucket / $this->getWidth()));
} else {
$bucketHeight = 0;
}
// Try to avoid reading from storage if the file was generated by this script
if (isset($this->tmpBucketedThumbCache[$bucket])) {
$tmpPath = $this->tmpBucketedThumbCache[$bucket];
if (file_exists($tmpPath)) {
return array('path' => $tmpPath, 'width' => $bucket, 'height' => $bucketHeight);
}
}
$bucketPath = $this->getBucketThumbPath($bucket);
if ($this->repo->fileExists($bucketPath)) {
$fsFile = $this->repo->getLocalReference($bucketPath);
if ($fsFile) {
return array('path' => $fsFile->getPath(), 'width' => $bucket, 'height' => $bucketHeight);
}
}
}
// Original file
return array('path' => $this->getLocalRefPath(), 'width' => $this->getWidth(), 'height' => $this->getHeight());
}