Summary: Ref T7707. Ref T2479. Ref T5258. The thumbnailing code is some of the only code in the codebase which doesn't use exceptions to handle errors. I'm going to convert it to use exceptions; make sure they do something reasonable at top level. Strategy here is: - By default, we just fall back to a placeholder image if anything goes wrong. - Later, I'll likely add a "debug" workflow from the new "Transforms" UI which will surface the specific exception instead (the code can't really raise any interesting exceptions right now). Test Plan: Faked an exception and saw some reasonable default images. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5258, T2479, T7707 Differential Revision: https://secure.phabricator.com/D12809
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
abstract class PhabricatorFileTransform extends Phobject {
|
|
|
|
abstract public function getTransformName();
|
|
abstract public function getTransformKey();
|
|
abstract public function canApplyTransform(PhabricatorFile $file);
|
|
abstract public function applyTransform(PhabricatorFile $file);
|
|
|
|
public function getDefaultTransform(PhabricatorFile $file) {
|
|
return null;
|
|
}
|
|
|
|
public function generateTransforms() {
|
|
return array($this);
|
|
}
|
|
|
|
public static function getAllTransforms() {
|
|
static $map;
|
|
|
|
if ($map === null) {
|
|
$xforms = id(new PhutilSymbolLoader())
|
|
->setAncestorClass(__CLASS__)
|
|
->loadObjects();
|
|
|
|
$result = array();
|
|
foreach ($xforms as $xform_template) {
|
|
foreach ($xform_template->generateTransforms() as $xform) {
|
|
$key = $xform->getTransformKey();
|
|
if (isset($result[$key])) {
|
|
throw new Exception(
|
|
pht(
|
|
'Two %s objects define the same transform key ("%s"), but '.
|
|
'each transform must have a unique key.',
|
|
__CLASS__,
|
|
$key));
|
|
}
|
|
$result[$key] = $xform;
|
|
}
|
|
}
|
|
|
|
$map = $result;
|
|
}
|
|
|
|
return $map;
|
|
}
|
|
|
|
}
|