[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorConduitConsoleController 4 extends PhabricatorConduitController { 5 6 private $method; 7 8 public function shouldAllowPublic() { 9 return true; 10 } 11 12 public function willProcessRequest(array $data) { 13 $this->method = $data['method']; 14 } 15 16 public function processRequest() { 17 18 $request = $this->getRequest(); 19 $viewer = $request->getUser(); 20 21 $method = id(new PhabricatorConduitMethodQuery()) 22 ->setViewer($viewer) 23 ->withMethods(array($this->method)) 24 ->executeOne(); 25 26 if (!$method) { 27 return new Aphront404Response(); 28 } 29 30 $can_call_method = false; 31 32 $status = $method->getMethodStatus(); 33 $reason = $method->getMethodStatusDescription(); 34 $errors = array(); 35 36 switch ($status) { 37 case ConduitAPIMethod::METHOD_STATUS_DEPRECATED: 38 $reason = nonempty($reason, pht('This method is deprecated.')); 39 $errors[] = pht('Deprecated Method: %s', $reason); 40 break; 41 case ConduitAPIMethod::METHOD_STATUS_UNSTABLE: 42 $reason = nonempty( 43 $reason, 44 pht( 45 'This method is new and unstable. Its interface is subject '. 46 'to change.')); 47 $errors[] = pht('Unstable Method: %s', $reason); 48 break; 49 } 50 51 $error_types = $method->defineErrorTypes(); 52 if ($error_types) { 53 $error_description = array(); 54 foreach ($error_types as $error => $meaning) { 55 $error_description[] = hsprintf( 56 '<li><strong>%s:</strong> %s</li>', 57 $error, 58 $meaning); 59 } 60 $error_description = phutil_tag('ul', array(), $error_description); 61 } else { 62 $error_description = pht( 63 'This method does not raise any specific errors.'); 64 } 65 66 $form = new AphrontFormView(); 67 $form 68 ->setUser($request->getUser()) 69 ->setAction('/api/'.$this->method) 70 ->addHiddenInput('allowEmptyParams', 1) 71 ->appendChild( 72 id(new AphrontFormStaticControl()) 73 ->setLabel('Description') 74 ->setValue($method->getMethodDescription())) 75 ->appendChild( 76 id(new AphrontFormStaticControl()) 77 ->setLabel('Returns') 78 ->setValue($method->defineReturnType())) 79 ->appendChild( 80 id(new AphrontFormMarkupControl()) 81 ->setLabel('Errors') 82 ->setValue($error_description)) 83 ->appendChild(hsprintf( 84 '<p class="aphront-form-instructions">Enter parameters using '. 85 '<strong>JSON</strong>. For instance, to enter a list, type: '. 86 '<tt>["apple", "banana", "cherry"]</tt>')); 87 88 $params = $method->defineParamTypes(); 89 foreach ($params as $param => $desc) { 90 $form->appendChild( 91 id(new AphrontFormTextControl()) 92 ->setLabel($param) 93 ->setName("params[{$param}]") 94 ->setCaption($desc)); 95 } 96 97 $must_login = !$viewer->isLoggedIn() && 98 $method->shouldRequireAuthentication(); 99 if ($must_login) { 100 $errors[] = pht( 101 'Login Required: This method requires authentication. You must '. 102 'log in before you can make calls to it.'); 103 } else { 104 $form 105 ->appendChild( 106 id(new AphrontFormSelectControl()) 107 ->setLabel('Output Format') 108 ->setName('output') 109 ->setOptions( 110 array( 111 'human' => 'Human Readable', 112 'json' => 'JSON', 113 ))) 114 ->appendChild( 115 id(new AphrontFormSubmitControl()) 116 ->addCancelButton($this->getApplicationURI()) 117 ->setValue(pht('Call Method'))); 118 } 119 120 $header = id(new PHUIHeaderView()) 121 ->setUser($viewer) 122 ->setHeader($method->getAPIMethodName()); 123 124 $form_box = id(new PHUIObjectBoxView()) 125 ->setHeader($header) 126 ->setFormErrors($errors) 127 ->setForm($form); 128 129 $crumbs = $this->buildApplicationCrumbs(); 130 $crumbs->addTextCrumb($method->getAPIMethodName()); 131 132 return $this->buildApplicationPage( 133 array( 134 $crumbs, 135 $form_box, 136 ), 137 array( 138 'title' => $method->getAPIMethodName(), 139 )); 140 } 141 142 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |