Differential D7499 Diff 16925 src/applications/harbormaster/storage/configuration/HarbormasterBuildStep.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/storage/configuration/HarbormasterBuildStep.php
<?php | <?php | ||||
final class HarbormasterBuildStep extends HarbormasterDAO { | final class HarbormasterBuildStep extends HarbormasterDAO | ||||
implements PhabricatorPolicyInterface { | |||||
protected $buildPlanPHID; | protected $buildPlanPHID; | ||||
protected $className; | |||||
protected $details = array(); | |||||
private $buildPlan = self::ATTACHABLE; | private $buildPlan = self::ATTACHABLE; | ||||
public function getConfiguration() { | public function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_SERIALIZATION => array( | |||||
'details' => self::SERIALIZATION_JSON, | |||||
) | |||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function generatePHID() { | public function generatePHID() { | ||||
return PhabricatorPHID::generateNewPHID( | return PhabricatorPHID::generateNewPHID( | ||||
HarbormasterPHIDTypeBuildStep::TYPECONST); | HarbormasterPHIDTypeBuildStep::TYPECONST); | ||||
} | } | ||||
public function attachBuildPlan(HarbormasterBuildPlan $plan) { | public function attachBuildPlan(HarbormasterBuildPlan $plan) { | ||||
$this->buildPlan = $plan; | $this->buildPlan = $plan; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getBuildPlan() { | public function getBuildPlan() { | ||||
return $this->assertAttached($this->buildPlan); | return $this->assertAttached($this->buildPlan); | ||||
} | } | ||||
public function getDetail($key, $default = null) { | |||||
return idx($this->details, $key, $default); | |||||
} | |||||
public function setDetail($key, $value) { | |||||
$this->details[$key] = $value; | |||||
return $this; | |||||
} | |||||
public function getStepImplementation() { | |||||
if ($this->className === null) { | |||||
throw new Exception("No implementation set for the given step."); | |||||
} | |||||
// TODO: We should look up the class in phutil's system to ensure | |||||
// that it actually extends BuildStepImplementation. | |||||
$class = $this->className; | |||||
epriestley: `is_subclass_of()` is a cheap way to nearly do this, although it won't test for abstract… | |||||
Not Done Inline ActionsI actually did the PhutilSymbolLoader stuff in D7500, so I'll backport it to this diff. hach-que: I actually did the PhutilSymbolLoader stuff in D7500, so I'll backport it to this diff. | |||||
$implementation = newv($class, array()); | |||||
Not Done Inline ActionsPrefer newv() for consistency. epriestley: Prefer `newv()` for consistency. | |||||
$implementation->loadSettings($this); | |||||
return $implementation; | |||||
} | |||||
Not Done Inline ActionsI believe this is impossible to reach. I don't know any way to make new return null and continue execution. epriestley: I believe this is impossible to reach. I don't know any way to make `new` return `null` and… | |||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */ | |||||
public function getCapabilities() { | |||||
return array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
); | |||||
} | |||||
public function getPolicy($capability) { | |||||
return $this->getBuildPlan()->getPolicy($capability); | |||||
} | |||||
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | |||||
Not Done Inline ActionsBuildStepQuery should load and attach BuildPlans unconditionally (in willFilterPage(array $page)) if the build plan is required for policy checks. epriestley: `BuildStepQuery` should load and attach `BuildPlans` unconditionally (in `willFilterPage(array… | |||||
return $this->getBuildPlan()->hasAutomaticCapability($capability, $viewer); | |||||
} | |||||
public function describeAutomaticCapability($capability) { | |||||
Not Done Inline ActionsFor consistency, call into the build plan to figure this out, too. epriestley: For consistency, call into the build plan to figure this out, too. | |||||
return pht('A build step has the same policies as its build plan.'); | |||||
Not Done Inline ActionsThis should be "its", I think. epriestley: This should be "its", I think. | |||||
} | |||||
} | } | ||||
Not Done Inline ActionsThis should probably return some string like "A build step has the same policies as its build plan." epriestley: This should probably return some string like "A build step has the same policies as its build… |
is_subclass_of() is a cheap way to nearly do this, although it won't test for abstract subclasses.
PhutilSymbolLoader can also do it, although it's like 10 lines long.