Path: blob/master/src/applications/files/transform/PhabricatorFileTransform.php
12242 views
<?php12abstract class PhabricatorFileTransform extends Phobject {34abstract public function getTransformName();5abstract public function getTransformKey();6abstract public function canApplyTransform(PhabricatorFile $file);7abstract public function applyTransform(PhabricatorFile $file);89public function getDefaultTransform(PhabricatorFile $file) {10return null;11}1213public function generateTransforms() {14return array($this);15}1617public function executeTransform(PhabricatorFile $file) {18if ($this->canApplyTransform($file)) {19try {20return $this->applyTransform($file);21} catch (Exception $ex) {22// Ignore.23}24}2526return $this->getDefaultTransform($file);27}2829public static function getAllTransforms() {30return id(new PhutilClassMapQuery())31->setAncestorClass(__CLASS__)32->setExpandMethod('generateTransforms')33->setUniqueMethod('getTransformKey')34->execute();35}3637public static function getTransformByKey($key) {38$all = self::getAllTransforms();3940$xform = idx($all, $key);41if (!$xform) {42throw new Exception(43pht(44'No file transform with key "%s" exists.',45$key));46}4748return $xform;49}5051}525354