public function getArtifactImplementation()
 {
     if ($this->artifactImplementation === null) {
         $type = $this->getArtifactType();
         $impl = HarbormasterArtifact::getArtifactType($type);
         if (!$impl) {
             return null;
         }
         $impl = clone $impl;
         $impl->setBuildArtifact($this);
         $this->artifactImplementation = $impl;
     }
     return $this->artifactImplementation;
 }
 public function createArtifact(PhabricatorUser $actor, $artifact_key, $artifact_type, array $artifact_data)
 {
     $impl = HarbormasterArtifact::getArtifactType($artifact_type);
     if (!$impl) {
         throw new Exception(pht('There is no implementation available for artifacts of type "%s".', $artifact_type));
     }
     $impl->validateArtifactData($artifact_data);
     $artifact = HarbormasterBuildArtifact::initializeNewBuildArtifact($this)->setArtifactKey($artifact_key)->setArtifactType($artifact_type)->setArtifactData($artifact_data);
     $impl = $artifact->getArtifactImplementation();
     $impl->willCreateArtifact($actor);
     return $artifact->save();
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $build_target_phid = $request->getValue('buildTargetPHID');
     $build_target = id(new HarbormasterBuildTargetQuery())->setViewer($viewer)->withPHIDs(array($build_target_phid))->executeOne();
     if (!$build_target) {
         throw new Exception(pht('No such build target "%s"!', $build_target_phid));
     }
     $artifact_type = $request->getValue('artifactType');
     // Cast "artifactData" parameters to acceptable types if this request
     // is submitting raw HTTP parameters. This is not ideal. See T11887 for
     // discussion.
     $artifact_data = $request->getValue('artifactData');
     if (!$request->getIsStrictlyTyped()) {
         $impl = HarbormasterArtifact::getArtifactType($artifact_type);
         if ($impl) {
             foreach ($artifact_data as $key => $value) {
                 $artifact_data[$key] = $impl->readArtifactHTTPParameter($key, $value);
             }
         }
     }
     $artifact = $build_target->createArtifact($viewer, $request->getValue('artifactKey'), $artifact_type, $artifact_data);
     return array('data' => $this->returnArtifactList(array($artifact)));
 }