1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 13:30:55 +01:00

Conduit: conduit.connect

This commit is contained in:
epriestley 2011-01-24 11:30:10 -08:00
parent dec8bac3a3
commit 9f026d7892
4 changed files with 106 additions and 2 deletions

View file

@ -47,6 +47,7 @@ phutil_register_library_map(array(
'AphrontWebpageResponse' => 'aphront/response/webpage',
'ConduitAPIMethod' => 'applications/conduit/method/base',
'ConduitAPIRequest' => 'applications/conduit/protocol/request',
'ConduitAPI_conduit_connect_Method' => 'applications/conduit/method/conduit/connect',
'ConduitAPI_differential_creatediff_Method' => 'applications/conduit/method/differential/creatediff',
'ConduitAPI_file_upload_Method' => 'applications/conduit/method/file/upload',
'ConduitException' => 'applications/conduit/protocol/exception',
@ -148,6 +149,7 @@ phutil_register_library_map(array(
'AphrontSideNavView' => 'AphrontView',
'AphrontTableView' => 'AphrontView',
'AphrontWebpageResponse' => 'AphrontResponse',
'ConduitAPI_conduit_connect_Method' => 'ConduitAPIMethod',
'ConduitAPI_differential_creatediff_Method' => 'ConduitAPIMethod',
'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod',
'DifferentialChangeset' => 'DifferentialDAO',

View file

@ -55,7 +55,7 @@ class PhabricatorConduitAPIController
if (isset($_REQUEST['params']) && is_array($_REQUEST['params'])) {
$params_post = $request->getArr('params');
foreach ($params_post as $key => $value) {
$params_post[$key] = json_decode($value);
$params_post[$key] = json_decode($value, true);
}
$params = $params_post;
} else {
@ -63,7 +63,7 @@ class PhabricatorConduitAPIController
if (!strlen($params_json)) {
$params = array();
} else {
$params = json_decode($params_json);
$params = json_decode($params_json, true);
if (!is_array($params)) {
throw new Exception(
"Invalid parameter information was passed to method ".

View file

@ -0,0 +1,88 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class ConduitAPI_conduit_connect_Method extends ConduitAPIMethod {
public function getMethodDescription() {
return "Connect a session-based client.";
}
public function defineParamTypes() {
return array(
'client' => 'required string',
'clientVersion' => 'required int',
'clientDescription' => 'optional string',
'user' => 'optional string',
);
}
public function defineReturnType() {
return 'dict<string, any>';
}
public function defineErrorTypes() {
return array(
"ERR-BAD-VERSION" =>
"Client/server version mismatch. Update your client.",
"ERR-UNKNOWN-CLIENT" =>
"Client is unknown.",
"ERR-UPDATE-ARC" =>
"Arcanist is now open source! Update your scripts/aliases to use ".
"'/home/engshare/devtools/arcanist/bin/arc' if you're running from ".
"a Facebook host, or see ".
"<http://www.intern.facebook.com/intern/wiki/index.php/Arcanist> for ".
"laptop instructions.",
);
}
protected function execute(ConduitAPIRequest $request) {
$client = $request->getValue('client');
$client_version = (int)$request->getValue('clientVersion');
$client_description = (string)$request->getValue('clientDescription');
// Log the connection, regardless of the outcome of checks below.
$connection = new PhabricatorConduitConnectionLog();
$connection->setClient($client);
$connection->setClientVersion($client_version);
$connection->setClientDescription($client_description);
$connection->setUsername((string)$request->getValue('user'));
$connection->save();
switch ($client) {
case 'arc':
$server_version = 2;
switch ($client_version) {
case 1:
throw new ConduitException('ERR-UPDATE-ARC');
case $server_version:
break;
default:
throw new ConduitException('ERR-BAD-VERSION');
}
break;
default:
throw new ConduitException('ERR-UNKNOWN-CLIENT');
}
return array(
'connectionID' => $connection->getID(),
);
}
}

View file

@ -0,0 +1,14 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/conduit/method/base');
phutil_require_module('phabricator', 'applications/conduit/protocol/exception');
phutil_require_module('phabricator', 'applications/conduit/storage/connectionlog');
phutil_require_source('ConduitAPI_conduit_connect_Method.php');