Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/transform/PhabricatorFileTransform.php
12242 views
1
<?php
2
3
abstract class PhabricatorFileTransform extends Phobject {
4
5
abstract public function getTransformName();
6
abstract public function getTransformKey();
7
abstract public function canApplyTransform(PhabricatorFile $file);
8
abstract public function applyTransform(PhabricatorFile $file);
9
10
public function getDefaultTransform(PhabricatorFile $file) {
11
return null;
12
}
13
14
public function generateTransforms() {
15
return array($this);
16
}
17
18
public function executeTransform(PhabricatorFile $file) {
19
if ($this->canApplyTransform($file)) {
20
try {
21
return $this->applyTransform($file);
22
} catch (Exception $ex) {
23
// Ignore.
24
}
25
}
26
27
return $this->getDefaultTransform($file);
28
}
29
30
public static function getAllTransforms() {
31
return id(new PhutilClassMapQuery())
32
->setAncestorClass(__CLASS__)
33
->setExpandMethod('generateTransforms')
34
->setUniqueMethod('getTransformKey')
35
->execute();
36
}
37
38
public static function getTransformByKey($key) {
39
$all = self::getAllTransforms();
40
41
$xform = idx($all, $key);
42
if (!$xform) {
43
throw new Exception(
44
pht(
45
'No file transform with key "%s" exists.',
46
$key));
47
}
48
49
return $xform;
50
}
51
52
}
53
54