]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Don't instantiate abstract classes in ArcanistConfiguration::buildAllWorkflows
authorMiorel-Lucian Palii <mlpalii@gmail.com>
Sat, 29 Jun 2013 01:24:30 +0000 (18:24 -0700)
committerMiorel-Lucian Palii <mlpalii@gmail.com>
Sat, 29 Jun 2013 01:24:30 +0000 (18:24 -0700)
Summary:
I wanted to write a couple of workflows that shared some code in an abstract superclass, but ##arc## would fail trying to instantiate the abstract class.

As it turns out, we can modernize the ##buildAllWorkflows## function a bit, and it will only load concrete objects.

Test Plan:
1. Define an abstract subclass of ##ArcanistBaseWorkflow##.
2. ##arc liberate## the source directory that contains it.
3. Try any ##arc## operation without this diff, and see it fail.
4. Patch this diff and see that ##arc## operations work now.

Reviewers: epriestley, vrana

Reviewed By: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D6324

src/configuration/ArcanistConfiguration.php

index 23d58c668d1fde72957a4aecff34ad219d3db92b..fe4a79bb8d734735c36d623f9e91608294e9f56c 100644 (file)
@@ -33,28 +33,25 @@ class ArcanistConfiguration {
   }
 
   public function buildAllWorkflows() {
-    $symbols = id(new PhutilSymbolLoader())
-      ->setType('class')
-      ->setAncestorClass('ArcanistBaseWorkflow')
-      ->selectAndLoadSymbols();
+    $workflows_by_name = array();
 
-    $workflows = array();
-    foreach ($symbols as $symbol) {
-      $class = $symbol['name'];
-      $workflow = newv($class, array());
+    $workflows_by_class_name = id(new PhutilSymbolLoader())
+      ->setAncestorClass('ArcanistBaseWorkflow')
+      ->loadObjects();
+    foreach ($workflows_by_class_name as $class => $workflow) {
       $name = $workflow->getWorkflowName();
 
-      if (isset($workflows[$name])) {
-        $other = get_class($workflows[$name]);
+      if (isset($workflows_by_name[$name])) {
+        $other = get_class($workflows_by_name[$name]);
         throw new Exception(
           "Workflows {$class} and {$other} both implement workflows named ".
           "{$name}.");
       }
 
-      $workflows[$workflow->getWorkflowName()] = $workflow;
+      $workflows_by_name[$name] = $workflow;
     }
 
-    return $workflows;
+    return $workflows_by_name;
   }
 
   final public function isValidWorkflow($workflow) {