Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / policy / management / PhabricatorPolicyManagementShowWorkflow.php
bloba378ecc07684f88f7907ccf5b2581293dee1ea76
1 <?php
3 final class PhabricatorPolicyManagementShowWorkflow
4 extends PhabricatorPolicyManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('show')
9 ->setSynopsis(pht('Show policy information about an object.'))
10 ->setExamples('**show** D123')
11 ->setArguments(
12 array(
13 array(
14 'name' => 'objects',
15 'wildcard' => true,
17 ));
20 public function execute(PhutilArgumentParser $args) {
21 $console = PhutilConsole::getConsole();
22 $viewer = $this->getViewer();
24 $obj_names = $args->getArg('objects');
25 if (!$obj_names) {
26 throw new PhutilArgumentUsageException(
27 pht('Specify the name of an object to show policy information for.'));
28 } else if (count($obj_names) > 1) {
29 throw new PhutilArgumentUsageException(
30 pht(
31 'Specify the name of exactly one object to show policy information '.
32 'for.'));
35 $object = id(new PhabricatorObjectQuery())
36 ->setViewer($viewer)
37 ->withNames($obj_names)
38 ->executeOne();
40 if (!$object) {
41 $name = head($obj_names);
42 throw new PhutilArgumentUsageException(
43 pht(
44 "No such object '%s'!",
45 $name));
48 $handle = id(new PhabricatorHandleQuery())
49 ->setViewer($viewer)
50 ->withPHIDs(array($object->getPHID()))
51 ->executeOne();
53 $policies = PhabricatorPolicyQuery::loadPolicies(
54 $viewer,
55 $object);
57 $console->writeOut("__%s__\n\n", pht('OBJECT'));
58 $console->writeOut(" %s\n", $handle->getFullName());
59 $console->writeOut("\n");
61 $console->writeOut("__%s__\n\n", pht('CAPABILITIES'));
62 foreach ($policies as $capability => $policy) {
63 $ref = $policy->newRef($viewer);
65 $console->writeOut(" **%s**\n", $capability);
66 $console->writeOut(" %s\n", $ref->getPolicyDisplayName());
67 $console->writeOut(" %s\n",
68 PhabricatorPolicy::getPolicyExplanation($viewer, $policy->getPHID()));
69 $console->writeOut("\n");
72 if ($object instanceof PhabricatorPolicyCodexInterface) {
73 $codex = PhabricatorPolicyCodex::newFromObject($object, $viewer);
75 $rules = $codex->getPolicySpecialRuleDescriptions();
76 foreach ($rules as $rule) {
77 echo tsprintf(
78 " - %s\n",
79 $rule->getDescription());
82 echo "\n";