Differential D20810 Diff 49617 src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php
<?php | <?php | ||||
final class PhabricatorEditEngineSubtype | final class PhabricatorEditEngineSubtype | ||||
extends Phobject { | extends Phobject { | ||||
const SUBTYPE_DEFAULT = 'default'; | const SUBTYPE_DEFAULT = 'default'; | ||||
private $key; | private $key; | ||||
private $name; | private $name; | ||||
private $icon; | private $icon; | ||||
private $tagText; | private $tagText; | ||||
private $color; | private $color; | ||||
private $childSubtypes = array(); | private $childSubtypes = array(); | ||||
private $childIdentifiers = array(); | private $childIdentifiers = array(); | ||||
private $fieldConfiguration = array(); | private $fieldConfiguration = array(); | ||||
private $mutations; | |||||
public function setKey($key) { | public function setKey($key) { | ||||
$this->key = $key; | $this->key = $key; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getKey() { | public function getKey() { | ||||
return $this->key; | return $this->key; | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public function setChildFormIdentifiers(array $child_identifiers) { | ||||
$this->childIdentifiers = $child_identifiers; | $this->childIdentifiers = $child_identifiers; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getChildFormIdentifiers() { | public function getChildFormIdentifiers() { | ||||
return $this->childIdentifiers; | return $this->childIdentifiers; | ||||
} | } | ||||
public function setMutations($mutations) { | |||||
$this->mutations = $mutations; | |||||
return $this; | |||||
} | |||||
public function getMutations() { | |||||
return $this->mutations; | |||||
} | |||||
public function hasTagView() { | public function hasTagView() { | ||||
return (bool)strlen($this->getTagText()); | return (bool)strlen($this->getTagText()); | ||||
} | } | ||||
public function newTagView() { | public function newTagView() { | ||||
$view = id(new PHUITagView()) | $view = id(new PHUITagView()) | ||||
->setType(PHUITagView::TYPE_OUTLINE) | ->setType(PHUITagView::TYPE_OUTLINE) | ||||
->setName($this->getTagText()); | ->setName($this->getTagText()); | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | foreach ($config as $value) { | ||||
array( | array( | ||||
'key' => 'string', | 'key' => 'string', | ||||
'name' => 'string', | 'name' => 'string', | ||||
'tag' => 'optional string', | 'tag' => 'optional string', | ||||
'color' => 'optional string', | 'color' => 'optional string', | ||||
'icon' => 'optional string', | 'icon' => 'optional string', | ||||
'children' => 'optional map<string, wild>', | 'children' => 'optional map<string, wild>', | ||||
'fields' => 'optional map<string, wild>', | 'fields' => 'optional map<string, wild>', | ||||
'mutations' => 'optional list<string>', | |||||
)); | )); | ||||
$key = $value['key']; | $key = $value['key']; | ||||
self::validateSubtypeKey($key); | self::validateSubtypeKey($key); | ||||
if (isset($map[$key])) { | if (isset($map[$key])) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | public static function validateConfiguration($config) { | ||||
if (!isset($map[self::SUBTYPE_DEFAULT])) { | if (!isset($map[self::SUBTYPE_DEFAULT])) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Subtype configuration is invalid: there is no subtype defined '. | 'Subtype configuration is invalid: there is no subtype defined '. | ||||
'with key "%s". This subtype is required and must be defined.', | 'with key "%s". This subtype is required and must be defined.', | ||||
self::SUBTYPE_DEFAULT)); | self::SUBTYPE_DEFAULT)); | ||||
} | } | ||||
foreach ($config as $value) { | |||||
$key = idx($value, 'key'); | |||||
$mutations = idx($value, 'mutations'); | |||||
if (!$mutations) { | |||||
continue; | |||||
} | |||||
foreach ($mutations as $mutation) { | |||||
if (!isset($map[$mutation])) { | |||||
throw new Exception( | |||||
pht( | |||||
'Subtype configuration is invalid: subtype with key "%s" '. | |||||
'specifies that it can mutate into subtype "%s", but that is '. | |||||
'not a valid subtype.', | |||||
$key, | |||||
$mutation)); | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
public static function newSubtypeMap(array $config) { | public static function newSubtypeMap(array $config) { | ||||
$map = array(); | $map = array(); | ||||
foreach ($config as $entry) { | foreach ($config as $entry) { | ||||
$key = $entry['key']; | $key = $entry['key']; | ||||
$name = $entry['name']; | $name = $entry['name']; | ||||
Show All 34 Lines | foreach ($config as $entry) { | ||||
if ($field_configurations) { | if ($field_configurations) { | ||||
foreach ($field_configurations as $field_key => $field_configuration) { | foreach ($field_configurations as $field_key => $field_configuration) { | ||||
$subtype->setSubtypeFieldConfiguration( | $subtype->setSubtypeFieldConfiguration( | ||||
$field_key, | $field_key, | ||||
$field_configuration); | $field_configuration); | ||||
} | } | ||||
} | } | ||||
$subtype->setMutations(idx($entry, 'mutations')); | |||||
$map[$key] = $subtype; | $map[$key] = $subtype; | ||||
} | } | ||||
return new PhabricatorEditEngineSubtypeMap($map); | return new PhabricatorEditEngineSubtypeMap($map); | ||||
} | } | ||||
public function newIconView() { | public function newIconView() { | ||||
return id(new PHUIIconView()) | return id(new PHUIIconView()) | ||||
->setIcon($this->getIcon(), $this->getColor()); | ->setIcon($this->getIcon(), $this->getColor()); | ||||
} | } | ||||
} | } |